Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The JavaScript FAQ
Prev Home Next

Error Handling Demo

Question: Can I change the JavaScript error handler without reloading the page?

Answer: Yes. To change the JavaScript error handler, just set window.onerror to the name of the function that will serve as your new error handler.

Here's a demo that lets you test three different error handlers:

  • the browser's default error handler
  • an error handler that displays a customized alert box
  • a "silent" error handler that suppresses all error messages.
    1. Use the select box to set or change the error handler.
    2. Click Fire an Error to test the active error handler.

    Below is the source code of the error handling functions used in this demo:

    function defaultHandler() {return false}
    function silentHandler()  {return true}
    function customHandler(desc,page,line,chr)  {
     alert(
      'JavaScript error occurred! \n'
     +'The error was handled by '
     +'a customized error handler.\n'
     +'\nError description: \t'+desc
     +'\nPage address:      \t'+page
     +'\nLine number:       \t'+line
     )
     return true
    }
    

    JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

    The JavaScript FAQ
    Prev Home Next


  •  
     
      Mirrored with kind permission of Alexei Kourbatov Design by Interspire