Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 10
Registered: ‎01-01-2014
My Device: Q10, SQN100-3
My Carrier: XL (Indonesia)
Accepted Solution

uncatchable exception

I use xhr to access local file. And having problems with handling when file not found.

 

If I do syncronious request - its fine.

 

var xhr = new XMLHttpRequest();

xhr.open("GET", "local:///data/leonardo_da_vinci.yml", false);

try { xhr.send(); } catch (e) { console.log(e) }

 

But if syncronious - I can't catch exception Smiley Sad

 

var xhr = new XMLHttpRequest();

xhr.open("GET", "local:///data/leonardo_da_vinci.yml", true); // <-- here "true" means async xhr

try { xhr.send(); } catch (e) { console.log(e) }

 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: uncatchable exception

[ Edited ]

Have you tried adding the onload and onerror functions to the xhr object? Example:

 

xhr.onerror = function (error) { ... }

The flow for synchronous and asynchronous will be different. In most cases, there's not often a good reason to go synchronous (i.e. blocking.)

 

Additional examples can be found here:

http://www.html5rocks.com/en/tutorials/cors/

http://www.html5rocks.com/en/tutorials/file/xhr2/

 

 

EDIT: The reason you won't catch the exception is that asynchronous means that the code will continue to run; we don't wait around to see if send() is successful or not. With the asynchronous approach you need to implement the appropriate callbacks to be alerted to success, errors, etc.


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Highlighted
Contributor
Posts: 10
Registered: ‎01-01-2014
My Device: Q10, SQN100-3
My Carrier: XL (Indonesia)

Re: uncatchable exception

Thank you!