1 //jls.loader.provide('jls.lang.Exception');
  2 
  3 jls.lang.Exception = jls.lang.Class.create(/** @lends jls.lang.Exception.prototype */
  4 {
  5     /**
  6      * @param {String} [message] The detail message.
  7      * @param {Object} [cause] The cause.
  8      * @constructs
  9      * @class Provide the base Exception.
 10      */
 11     initialize : function(message, cause, name) {
 12         /**
 13          * The detail message
 14          * 
 15          * @private
 16          * @type String
 17          */
 18         this._message = message || null;
 19         /**
 20          * The cause
 21          * 
 22          * @private
 23          * @type Object
 24          */
 25         this._cause = null;
 26         if (cause) {
 27             this._cause = jls.lang.Exception.wrap(cause);
 28         }
 29         this._name = name || null;
 30     },
 31     /**
 32      * Returns the cause of this exception or null if the cause is nonexistent or unknown. The cause is the exception that caused this
 33      * exception to get thrown.
 34      * 
 35      * @returns {Object} The cause.
 36      */
 37     getCause : function() {
 38         return this._cause;
 39     },
 40     /**
 41      * Returns the detail message string of this exception.
 42      * 
 43      * @returns {String} The detail message.
 44      */
 45     getMessage : function() {
 46         return this._message;
 47     },
 48     getName : function() {
 49         return this._name || jls.loader.getClassname(this) || 'jls.lang.Exception';
 50     },
 51     /**
 52      * Returns the stack trace of this exception.
 53      * 
 54      * @returns {Array} The stack trace.
 55      */
 56     getStackTrace : function() {
 57         return [];
 58     },
 59     /**
 60      * Prints this exception and its stacktrace.
 61      * 
 62      * @param {jls.io.PrintStream} [ps] The print stream to use.
 63      */
 64     printStackTrace : function(ps) {
 65     },
 66     /**
 67      * Returns a short description of this exception.
 68      * 
 69      * @returns {String} The detail message.
 70      */
 71     toString : function() {
 72         var msg = this.getMessage();
 73         if (msg == null) {
 74             return this.getName();
 75         } else {
 76             return this.getName() + ': ' + msg;
 77         }
 78     }
 79 });
 80 
 81 Object.extend(jls.lang.Exception, /** @lends jls.lang.Exception */
 82 {
 83     wrap : function(e) {
 84         if (e instanceof jls.lang.Exception) {
 85             return e;
 86         } else {
 87             return new jls.lang.Exception(e == null ? undefined : e.toString());
 88         }
 89     }
 90 });
 91 
 92