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
New Contributor
pavel-evst
Posts: 9
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 :smileysad:

 

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) }

 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,557
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.
Please use plain text.
New Contributor
pavel-evst
Posts: 9
Registered: ‎01-01-2014
My Device: Q10, SQN100-3
My Carrier: XL (Indonesia)

Re: uncatchable exception

Thank you!
Please use plain text.