Creating custom exceptions

Any project in the world may need exceptions. Exceptions are a modern and solid way of throwing errors for later handling them.

Creating new exception types is easy: it is just about deriving the $global.joopl.ExceptionBase** class:

$namespace.register("joopl.Samples");

$namespace.register("jOOPL.Samples", function () {
    this.MyException = $def({
        $constructor: function () {
            this.$base.$ctor({ message: "My custom exception message" });
        },
        $members: {
        },
        $extends: $global.joopl.ExceptionBase
    });
});

// Throwing the exception.
throw new $global.joopl.Samples.MyException();

Last edited Apr 6, 2013 at 1:21 PM by MFidemraizer, version 3

Comments

No comments yet.