A wrapper class for the native JavaScript Error object that adds a few useful capabilities for handling
errors in an Ext application. When you use Ext.Error to {@link #raise} an error from within any class that
uses the Ext 4 class system, the Error class can automatically add the source class and method from which
-the error was raised. It also includes logic to automatically log the eroor to the console, if available,
+the error was raised. It also includes logic to automatically log the eroor to the console, if available,
with additional metadata about the error. In all cases, the error will always be thrown at the end so that
execution will halt.
-Ext.Error also offers a global error {@link #handle handling} method that can be overridden in order to
+Ext.Error also offers a global error {@link #handle handling} method that can be overridden in order to
handle application-wide errors in a single spot. You can optionally {@link #ignore} errors altogether,
although in a real application it's usually a better idea to override the handling function and perform
logging or some other method of reporting the errors in a way that is meaningful to the application.
#Example usage:#
Ext.Error.raise('Something bad happened!');
-
+
If raised from plain JavaScript code, the error will be logged to the console (if available) and the message
displayed. In most cases however you'll be raising errors from within a class, and it may often be useful to add
additional metadata about the error being raised. The {@link #raise} method can also take a config object.
added to the error object and, if the console is available, logged to the console for inspection.
#Example usage:#
-
+
Ext.define('Ext.Foo', {
doSomething: function(option){
if (someCondition === false) {
msg: "You cannot do that!"
sourceClass: "Ext.Foo"
sourceMethod: "doSomething"
-
+
uncaught exception: You cannot do that!
-As you can see, the error will report exactly where it was raised and will include as much information as the
+As you can see, the error will report exactly where it was raised and will include as much information as the
raising code can usefully provide.
-If you want to handle all application errors globally you can simply override the static {@link handle} method
+If you want to handle all application errors globally you can simply override the static {@link #handle} method
and provide whatever handling logic you need. If the method returns true then the error is considered handled
and will not be thrown to the browser. If anything but true is returned then the error will be thrown normally.
//notify: Ext.isIE6 || Ext.isIE7,
<span id='Ext-Error-method-raise'> /**
-</span>Raise an error that can include additional data and supports automatic console logging if available.
-You can pass a string error message or an object with the `msg` attribute which will be used as the
-error message. The object can contain any other name-value attributes (or objects) to be logged
+</span>Raise an error that can include additional data and supports automatic console logging if available.
+You can pass a string error message or an object with the `msg` attribute which will be used as the
+error message. The object can contain any other name-value attributes (or objects) to be logged
along with the error.
-Note that after displaying the error message a JavaScript error will ultimately be thrown so that
+Note that after displaying the error message a JavaScript error will ultimately be thrown so that
execution will halt.
#Example usage:#
}
}
});
- * @param {String/Object} err The error message string, or an object containing the
+ * @param {String/Object} err The error message string, or an object containing the
* attribute "msg" that will be used as the error message. Any other data included in
* the object will also be logged to the browser console, if available.
* @static
dump: err,
stack: true
});
-
+
throw new Ext.Error(err);
}
},
name: 'Ext.Error',
<span id='Ext-Error-method-constructor'> /**
-</span> * @constructor
- * @param {String/Object} config The error message string, or an object containing the
+</span> * @param {String/Object} config The error message string, or an object containing the
* attribute "msg" that will be used as the error message. Any other data included in
* the object will be applied to the error instance and logged to the browser console, if available.
*/
},
<span id='Ext-Error-method-toString'> /**
-</span>Provides a custom string representation of the error object. This is an override of the base JavaScript
-`Object.toString` method, which is useful so that when logged to the browser console, an error object will
+</span>Provides a custom string representation of the error object. This is an override of the base JavaScript
+`Object.toString` method, which is useful so that when logged to the browser console, an error object will
be displayed with a useful message instead of `[object Object]`, the default `toString` result.
The default implementation will include the error message along with the raising class and method, if available,
//<debug>
(function () {
var prevOnError, timer, errors = 0,
- extraordinarilyBad = /(out of stack)|(too much recursion)|(stack overflow)|(out of memory)/i;
+ extraordinarilyBad = /(out of stack)|(too much recursion)|(stack overflow)|(out of memory)/i,
+ win = Ext.global;
+
+ if (typeof window === 'undefined') {
+ return; // build system or some such environment...
+ }
// This method is called to notify the user of the current error status.
function notify () {
} else if (counters.error) {
msg = '*** ' + msg;
}
- window.status = msg;
+ win.status = msg;
}
// Display an alert on the first error:
Ext.Error.notify = false;
if (timer) {
- window.clearInterval(timer); // ticks can queue up so stop...
+ win.clearInterval(timer); // ticks can queue up so stop...
timer = null;
}
// (Opera/Safari) and is the only way to update the status bar for warnings and other
// non-errors.
function poll () {
- timer = window.setInterval(notify, 1000);
+ timer = win.setInterval(notify, 1000);
}
// window.onerror is ideal (esp in IE) because you get full context. This is harmless
// otherwise (never called) which is good because you cannot feature detect it.
- prevOnError = window.onerror || Ext.emptyFn;
- window.onerror = function (message) {
+ prevOnError = win.onerror || Ext.emptyFn;
+ win.onerror = function (message) {
++errors;
if (!extraordinarilyBad.test(message)) {