Sign in to follow this  
gludington

Catching Raised Errors?

Recommended Posts

Perhaps this is a simple question, but how does one catch and stop propagation of raised errors? If flash is not present (asked for a replacement for the infosoftglobalutil flash detection public API/event in another thread), I am

 

chart.addEventListener('internal.domelementcreated', function(evt, status) {
if (status.success === false) {
	me.flashNotSupportedMsg();
	evt.stopPropagation();
}
});

 

This adds the correct message, however, a setXMLURL call has already been dispatched, because, with the deprecation of the infosoft globalutils, there is no way to detect flash and abort earlier in the process. A RenderManager Error is raised, which I listen for with:

 

chart.addEventListener('Error', function(evt, args) {
alert('error' + evt + ' ' + args.message);
evt.stopPropagation();
});

 

And, while the alert statement is triggered, the error also bubbles through to the browser. How can I trap the error so that my code can handle it, without an ugly browser error popup after I have already dealt with it?

Share this post


Link to post
Share on other sites

Looking through FusionCharts.debug.js, it seems this is the culprit on line 677:

 

           // Throw error in a separate scope so that the execution of this script
           // is not blocked. Do this only when debugMode is enabled
           window.setTimeout(function () {
               throw err;
           }, 0);

 

Because it is thrown in a different context, the error can only be caught in a global window.onerror listener, which has problems in some browsers. Judging from the comments, this should be:

 

           // Throw error in a separate scope so that the execution of this script
           // is not blocked. Do this only when debugMode is enabled
           if (global.core.debugMode.enabled()) {
            window.setTimeout(function () {
                throw err;
            }, 0);
           }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this