简体   繁体   中英

How can I know if a Javascript exception occurred in a PhoneGap application? (Android)

How can I know if a Javascript exception occurred in a PhoneGap application?

I'm using HTC Desire Z and Android 2.2.

I don't see anything in logcat and jsconsole.com does not seem to support exception transporting.

Using console.log to trac every exception is bit hard. Is there a solution for this or is this just how it is with Phonegap?

EDIT: It seems to be possible to capture at least some of exceptions with some really hacky wrappers . This some times can put you on the right track, but probably has some serious side effects and it won't certainly capture all the exceptions.

Uncaught exceptions should show up in logcat - at least the message and line number.

Otherwise you don't have many options. window.onerror does not work in Android AFAIK.

Is your question about logging the exceptions or about debugging them during development?

I'm not sure about the best way of logging them, but to debug them you can use Weinre .

I just wrote about Weinre on another very similar question ( https://stackoverflow.com/a/9252262/172973 )

Basically it's a remote javascript debugger for phonegap. You can either setup your own Weinre server, or use the one at http://debug.phonegap.com/

From a recent post from the PhoneGap blog:

It's a mobile browser! How am I supposed to debug it! The answer is that you aren't. You are going to debug your HTML, CSS, and JavaScript app in a desktop browser. The trick is to remove any dependencies that you have on PhoneGap before debugging.

http://www.phonegap.com/2011/05/18/debugging-phonegap-javascript/

Only if the desktop browser would work exactly like the mobile one...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM