exception-safe code

1. fixed gcc compiling error.
2. add exception.