R
Robert
Hi,
I thought it would be a good idea to make specialised error objects. So
I did something like this:
function IndexOutOfBoundsException(message)
{
Error.call(this, message);
}
IndexOutOfBoundsException.prototype = new Error();
....
throw new IndexOutOfBoundsException("bla");
I expected that I could use error.message after throwing
IndexOutOfBoundsException to retrieve the error message, but that
doesn't work. I just get an uncaught exception: Error.
Of course I can do
function IndexOutOfBoundsException(message)
{
this.message = message;
}
But I felt that the first example was better because
IndexOutOfBoundsException should have everything that an Error has.
Any comments why the first example does not work is appreciated.
I thought it would be a good idea to make specialised error objects. So
I did something like this:
function IndexOutOfBoundsException(message)
{
Error.call(this, message);
}
IndexOutOfBoundsException.prototype = new Error();
....
throw new IndexOutOfBoundsException("bla");
I expected that I could use error.message after throwing
IndexOutOfBoundsException to retrieve the error message, but that
doesn't work. I just get an uncaught exception: Error.
Of course I can do
function IndexOutOfBoundsException(message)
{
this.message = message;
}
But I felt that the first example was better because
IndexOutOfBoundsException should have everything that an Error has.
Any comments why the first example does not work is appreciated.