randunel/imacros

Doesn't work try catch syntax in javascript

Closed this issue · 2 comments

Hi!
I write some script using js in firefox.
But i can't use try catch syntax.

function NotImplementedError(message) {
    this.name = "NotImplementedError";
    this.message = (message || "");
}
NotImplementedError.prototype = Error.prototype;

try {
    var e = new NotImplementedError("NotImplementedError message");
    throw e;
} catch (ex1) {
    alert(ex1.stack);
    alert("ex1 instanceof NotImplementedError = " + (ex1 instanceof NotImplementedError));
    alert("ex1 instanceof Error = " + (ex1 instanceof Error));
    alert("ex1.name = " + ex1.name);
    alert("ex1.message = " + ex1.message);
}

Error:

TypeError: ex1 is undefined

But it valid js code.
Could you help me?

Hello @medliii.

You are using inheritance the wrong way. Specifically, your code doesn't work because of Something.prototype = SomethingElse.prototype.

You should direct questions such as this one to stackoverflow.

It doesn't work even without inheritance:

try {
    throw new Error("NotImplementedError message");
} catch (ex1) {
    alert("ex1 instanceof Error = " + (ex1 instanceof Error));
    alert("ex1.name = " + ex1.name);
    alert("ex1.message = " + ex1.message);
}

TypeError: ex1 is undefined, line 5