Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: What happens to JavaScript exceptions?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What happens to JavaScript exceptions?



Hi John.

After looking through the WebScriptObject implementation, I don't think there's an easy way to access exceptions from Objc. Both - evaluateWebScript and -callWebScriptMethod discard exceptions and return 'undefined' instead. You may want to file an enhancement request about that.

The best work-around I can suggest is to wrap your scripts inside a function with a try/catch block, and have the function return the exception information you're interested in. You can do that in the script files themselves, or in the call to -evaulateWebScript. The latter would work like this:

NSString* script = "function __wrapper() { try { return executeMyScript(); } catch (exception) { return exception; } } __wrapper();";
[[webView windowScriptObject] evaluateWebScript:script];


Hope that helps.

Geoff

On Apr 12, 2006, at 11:25 AM, John Anderson wrote:

I'm trying to write an automated test tool which loads a page and executes a series of JavaScripts. However, I can't figure out how to know when an exception is thrown.

How can I catch JavaScript exceptions in my WebKit Obj-C app code?

John

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webkitsdk-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webkitsdk-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >What happens to JavaScript exceptions? (From: John Anderson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.