Dealing with exception and error code