Document Information

Last modified:
2007/12/05 09:43 by jrass

JavaScript Error Handling

Errors

When a runtime error occurs, web browsers show specified error messages and may offer the possibility to examine this error with an debugger.

By applying an function pointer to window.onerror, it is possible to handle this error by the specified function and optionally disable the browser’s error handling by returning true.

window.onerror = handleError;

The function takes three parameters:

  • message the error message
  • location filename of the script containing the erroneous code
  • number the error’s code number
function handleError(message, url, code){
  //..
  return true;
}

Unfortunately, every browser behaves a bit different:

  • Internet Explorer handles errors to the given function
  • Firefox handles errors and can handle uncaught exceptions to the function
  • Safari only shows the error in the JavaScript Console
  • Opera might show the error in the error console

Exceptions

Thrown exceptions can be handled to a specified function to perform further examinations.

try
{
  var foo = '';
  foo.bar();
}
catch (exception)
{
  handleException(exception)
}

The exception object contains the following properties:

  • name the name of the exception (e.g. TypeError, SyntaxError)
  • message a text describing the error

In some browsers the object has more properties:

  • Internet Explorer:
    • number error code
    • description description of the error (mostly identical to message)
  • Firefox:
    • stack call stack
    • fileName name of the script containing the erroneous code
    • lineNumber line which contains the error

In Opera the message property contains the call stack.

Information

Last modified:
2007/12/05 09:43 by jrass

Account

Not logged in

 
 

Job Offers

To further improve qooxdoo we are seeking javascript developers. Read more...

Rich Ajax Platform (RAP)

RAP uses qooxdoo, Java and the Eclipse development model to build rich web applications. Read more...

qooxdoo Web Toolkit (QWT)

Similar to GWT this framework allows to create impressive qooxdoo applications just using Java. Read more...

Pustefix

Pustefix is a MVC-based web application framework using Java and XML/XSLT. Read more...

 
SourceForge.net Logo

Bad Behavior has blocked 0 potential spam attempts in the last 7 days.