Home

Keebler/Blog

« Top search keyphrases
Greasemap »

Custom Javascript Error Handler

Since I tend to be writing a lot of AJAX lately, which usually involves a fairly large Javascript program, it is easy to introduce Javascript errors that aren’t within a try-catch or are only produced in obscure web-browsers.  To make sure the public never gets a browser-prompt about an error, I’ve begun writing custom error handlers.  In theory, they could log the event or execute some code to deal with the error, however, most of the time I’m happy to just cover it up/display it in an understated way. 

The following Javascript will display the line number and error message in an HTML entity (e.g. a DIV) with an id "jserrors".  I have it running on my blog now so click here to generate a JS error and look at the very bottom of the page to see the error message. (Doesn’t work in Konqueror)

<script language="javascript">
window.onerror = function( msg, page, line )
{
if( document.getElementById("jserrors") )
{
document.getElementById("jserrors").innerHTML += line + ": " + msg + "<br/>";
}
return true;
}
</script>

Related Posts

  • Console² Firefox Javascript Error Console
  • Passport Canada is Error 500′d to Hell
  • Javascript In-Page Search Engine
  • FireBug Javascript Console
  • Ten good practices for writing JavaScript in 2005

This entry was posted on Sunday, July 3rd, 2005 at 1:56 pm and is filed under Web Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Custom Javascript Error Handler”

  1. Daniel F says:
    July 3, 2005 at 5:56 pm

    Ooh, that I like a whole lot. Good job!

  2. MrHappy says:
    July 3, 2005 at 6:11 pm

    Doesn’t seem to work in Safari either, probably since they’re built off the same core libraries. You really should get a Mac at some point, otherwise it’s going to continue to be the bane of your AJAX existence ;)

  3. Jonathan says:
    July 3, 2005 at 6:15 pm

    Probably Safari and Konquer don’t like the window.onload syntax. I’d bet the window.addEventListener/window.attachEvent functions would work. If someone buys me a Powerbook, I’ll write the code myself :D

Leave a Reply

Click here to cancel reply.

  • Blog Home

  • Tags

    90210 alessandra ambrosio animals asp.net audrina patridge battlestar galactica bikini bunny bush C# canada canada election ctv ctvglobemedia development Election Entertainment/Celebrity facebook Gordon Ramsay gorilla gossip girl hayden panettiere iphone last.fm liveblog liveblogging mesh08 muchmusic Music obama palin rachel bilson scribblelive shenae grimes subway telemarketers the hills the killers the office toronto ttc toronto tv us election video yeah yeah yeahs

    WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

  • Recent Posts

    • Trying to convince @idiotbante…
    • I wonder if the CTV “Save Loca…
    • Just finished dinner which I m…
    • I shouldn’t get as excited abo…
    • Stormtroopers’ 9/11 http://tin…
  • Categories

    • Election
    • Entertainment/Celebrity
    • Fake News
    • Featured
    • Funny
    • Keebler/Show
    • Music
    • My Releases
    • On-the-Road
    • RedDot
    • Reviews
    • Science/Technology
    • ScribbleLive
    • Security
    • Software
    • Torrent Live Stats
    • Tweets
    • Uncategorized
    • Web Development
  • Blogroll

    • Kitten-Monkey’s Cell
    • :: kattekylling ::
    • Adam Finley
    • blog-j
    • fuzzz.gaulin.ca
    • Idiot Banter
    • mad.greyarea.com
    • ob.blog
    • PollyPrissyPants
    • RedDot CMS Users Google Group
    • ScribbleLive Official Blog
  • My Sites

    • Flickr2Facebook
    • RedDot CMS
    • ScribbleLive
    • Where are my f(acebook)ing friends?
    • WhyYouShould