4 ms·
I usually put a safety check at the top of my code, ensuring that console and console.log exist (and, if they don't, defining something appropriate in their pla
by smanek 16y ago
I usually put a safety check at the top of my code, ensuring that console and console.log exist (and, if they don't, defining something appropriate in their place).
- remi 16y agoif (!window.console) { window.console = { log:function(){}, debug:function(){}, trace:function(){} }; }
- DougWebb 16y agoI just use: if ( errror ) { try { console.error(msg); } catch(e) {}; } Of course I do all of my debugging in Firefox with Firebug, and my goal is to ensure that these errors don't happen in production code so other browsers never hit the try/catch block. In rare cases where an error only happens in IE, I can throw an alert into the catch.
- CoryMathews 16y agoIts terrible practice to catch an error and do nothing with it.
- DougWebb 16y agoGenerally yes, I agree. But in this case all I'm doing with the error is displaying it to the programmer, and it doesn't matter to me if the programmer has to be using Firefox to see it. We were talking about displaying debugging messages and dealing with a missing console, not handling application failures.