/**
 * JSRuntimeException - Basisklasse f?r Exception-Handling
 *
 */
function JSRuntimeException(msg, cause)
{
    this._init(msg, cause);
}


JSRuntimeException.prototype._init = function(msg, cause)
{
    this._message = "";
    this._cause = null;

    if (typeof(msg) == "string" && msg.length > 0) {
        this._message = msg;
    }
    if (cause != undefined) {
        this.initCause(cause);
    }
}


JSRuntimeException.prototype.initCause = function(cause)
{
    if (this._cause == null) {
        if (cause instanceof JSInvalidArgumentException) {
            this._cause = cause;
        } else {
            throw new JSInvalidArgumentException("exception cause must be a instance of a subclass of JSInvalidArgumentException");
        }
    } else {
        throw new JSInvalidArgumentException("the cause for this exception has already been initialized");
    }
}


JSRuntimeException.prototype.getMessage = function()
{
    return this._message;
}


JSRuntimeException.prototype.getCause = function()
{
    return this._cause;
}


JSRuntimeException.prototype.toString = function()
{
    var constr = this.constructor.toString();
    var classname = constr.substring(constr.indexOf(" "), constr.indexOf("("));
    return classname + ": " + this.getMessage();
}


/**
 * JSInvalidArgumentException
 *
 */
// explicitly inhert from Object (just to keep the code coherent) 
JSInvalidArgumentException.prototype = new JSRuntimeException();
JSInvalidArgumentException.prototype.constructor = JSInvalidArgumentException;
JSInvalidArgumentException.superClass = JSRuntimeException.prototype;


function JSInvalidArgumentException(msg, cause)
{
    JSInvalidArgumentException.superClass._init.call(this, msg, cause);
}


/**
 * JSInvalidElementIdException
 *
 */
// explicitly inhert from Object (just to keep the code coherent) 
JSInvalidElementIdException.prototype = new JSRuntimeException();
JSInvalidElementIdException.prototype.constructor = JSInvalidElementIdException;
JSInvalidElementIdException.superClass = JSRuntimeException.prototype;


function JSInvalidElementIdException(msg, cause)
{
    JSInvalidElementIdException.superClass._init.call(this, msg, cause);
}


/**
 * JSDoesNotSupportException
 *
 */
// explicitly inhert from Object (just to keep the code coherent) 
JSDoesNotSupportException.prototype = new JSRuntimeException();
JSDoesNotSupportException.prototype.constructor = JSDoesNotSupportException;
JSDoesNotSupportException.superClass = JSRuntimeException.prototype;


function JSDoesNotSupportException(msg, cause)
{
    JSDoesNotSupportException.superClass._init.call(this, msg, cause);
}


/**
 * JSNotImplementedException
 *
 */
// explicitly inhert from Object (just to keep the code coherent) 
JSNotImplementedException.prototype = new JSRuntimeException();
JSNotImplementedException.prototype.constructor = JSNotImplementedException;
JSNotImplementedException.superClass = JSRuntimeException.prototype;


function JSNotImplementedException(msg, cause)
{
    JSNotImplementedException.superClass._init.call(this, msg, cause);
}
