Adding handling for exceptions in the native code