PDA

View Full Version : Error logging and exception handling in ExtJS



derekgray
21 Mar 2013, 9:35 AM
Alright, so we all know that Javascript is looser than... some undesirable thing, and that can make it hard to debug at times. I really do appreciate the effort the team at Sencha puts into their API, though one thing I still find lacking is runtime error handling. For instance, say I define a view and forget the 'extend' config. Instead of getting "Object [object Object] has no method 'onAdded'" in my console, what if I got something like: "Error adding component to layout: one or more passed arguments is not a valid component or component config." followed by a console.log of the arguments passed for reference?

That is my short and sweet wishlist for 4.3 whenever that rolls around: full-blown error and exception handling and logging. ~o)

scottmartin
21 Mar 2013, 2:31 PM
This may be of interest to you:
http://www.sencha.com/forum/showthread.php?228383

16 Jul 2013, 1:31 AM
I don't get it why no one else seems to run into this issue. This is on my shortlist too!

For anyone puzzling how to get stack traces of errors in a production environment, after hours of digging through options i ended up with something hackish like: (for defer()-ed calls)



window.oldSetTimeout = window.setTimeout;
window.setTimeout = function (func, delay) {
window.oldSetTimeout(function () {
try { func(); }
catch (exception) { // YOUR ERROR HANDLER HERE }
}, delay);
};


Before Ext is loaded, than: : (for Ajax-ed calls)



Ext.override(Ext.data.Connection, {
onStateChange : function () { //request, xdrResult
try {
this.callParent(arguments);
} catch (ex) {
// YOUR ERROR HANDLER HERE
}
}
});



Right after Ext, before your Application is loaded.

Than add u huge try{} catch{} block in your Ext Application launch().

Any better solutions would be appreciated!