3

I am building a Hybrid application using Phonegap on Android, their is a scenario where I am calling java API from JavaScript using Android WebView.

I want to catch exception in JavaScript if any exception occur while executing Java Native API. When I execute this it works but when Java Native code throws Exception application crashes and gives below exception in logs

05-06 21:28:03.230: W/dalvikvm(705): JNI WARNING: JNI method called with exception raised

05-06 21:28:03.239: E/dalvikvm(705): VM aborting

Java Native Code:

public Object callNative() throws Exception {
    throw new Exception("Exception Occured");
}

JavaScript Code:

try {
   window.callNative();
} catch(e) {
    // Exception Caught
}

1 Answer 1

1

I do not believe you are calling your intended method from JavaScript:

window.callNative("STRING PARAMETER VALUE");

According to your example, you are calling a different, likely undeclared method:

window.callNative();

Change your code to call the method I supply in the first code block.

1
  • Sorry Josh that's my mistake but the issue is something else, how to handle exception in JavaScript if its thrown from native Java May 7, 2013 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.