Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Error.html
index 0ab0e35..107059a 100644 (file)
 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.
@@ -37,7 +37,7 @@ At its simplest you can simply raise an error as a simple string from within any
 #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.
@@ -45,7 +45,7 @@ In this form the `msg` attribute becomes the error description, and any other da
 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) {
@@ -67,13 +67,13 @@ If a console is available (that supports the `console.dir` function) you'll see
     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.
 
@@ -132,12 +132,12 @@ This flag is not used in a release build.
         //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:#
@@ -157,7 +157,7 @@ execution will halt.
             }
         }
     });
-         * @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 &quot;msg&quot; 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
@@ -189,7 +189,7 @@ execution will halt.
                     dump: err,
                     stack: true
                 });
-                
+
                 throw new Ext.Error(err);
             }
         },
@@ -224,8 +224,7 @@ error to the browser, otherwise the error will be thrown and execution will halt
     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 &quot;msg&quot; 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.
      */
@@ -243,8 +242,8 @@ error to the browser, otherwise the error will be thrown and execution will halt
     },
 
 <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,
@@ -273,7 +272,12 @@ a particular error instance, if you want to provide a custom description that wi
 //&lt;debug&gt;
 (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 () {
@@ -290,7 +294,7 @@ a particular error instance, if you want to provide a custom description that wi
             } else if (counters.error) {
                 msg = '*** ' + msg;
             }
-            window.status = msg;
+            win.status = msg;
         }
 
         // Display an alert on the first error:
@@ -301,7 +305,7 @@ a particular error instance, if you want to provide a custom description that wi
             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;
             }
 
@@ -314,13 +318,13 @@ a particular error instance, if you want to provide a custom description that wi
     // (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)) {