Class: Exception

barejs.Exception(_message, _creatorFnopt)

Exception creates a normalized base class for creating custom Error (Exception) classes to throw. It handles determining the stack trace for the created exception in a cross browser way. This class relies on the constructor property being set correctly, otherwise sub-class constructors may show up in the stack trace. Using decl.declareClass to define base classes ensures the constructor property is set correctly.

Sub classes should also set the name property on the prototype to the name of the exception, for example:

 function MyCustomError( _message, _myAdditionalData )
 {
     Exception.call( this, _message );

     this.myAdditionalData = _myAdditionalData;
 }

 decl.declareClass( MyCustomError, Exception,
 {
     // Setting the name ensures our custom error looks and behaves as expected
     // Avoid using MyCustomError.name (named function name) as the name may get
     // mangled by a minifier/uglifier.
     name: "MyCustomError",

     myAdditionalData: null
 } );

Constructor

new Exception(_message, _creatorFnopt)

The Exception constructor will set up the exception with a name and stack property. You can pass the "creator function" as second argument, this is the topmost function that will be ignored from the stack. It defaults to the constructed object's constructor, which ensures the "Exception" and parent constructors never show up in the stack.

Parameters:
Name Type Attributes Description
_message string

The message that describes the exception.

_creatorFn function <optional>

Optional: function to exclude from the call stack. Defaults to the this.constructor function.

Source:

Members

name :string

The name of the Exception type. Base classes are supposed to set the correct name on the prototype too. It is recommended not to use the constructor function's name for this, as that might get obfuscated by a minifier, or the name property may not be supported at all.

Type:
  • string
Source: