Javascript's native Error objects are not instances of java.lang.Throwable which can be verified with the following code
Throwable error = null;
/** @j2sNative error = new Clazz.Error(); */
assert !(error instanceof Throwable); // pass
However, loading java.lang.Error class before instanceof Throwable is invoked for the first time causes consecutive instance checks to be true
var _ignored = Error.class;
Throwable error = null;
/** @j2sNative error = new Clazz.Error(); */
assert !(error instanceof Throwable); // fail
Additionally, if the instance test was performed at least once, loading the java.lang.Error class has no effect
Throwable error = null;
/** @j2sNative error = new Clazz.Error(); */
assert !(error instanceof Throwable); // pass
var _ignored = Error.class;
assert !(error instanceof Throwable); // also pass
The relation is non-transitive for subclasses of Error i.e. TypeError is Error and Error is Throwable, but TypeError is not Throwable
Throwable error = null, typeError = null;
/** @j2sNative
* error = new Clazz.Error();
* typeError = new TypeError(); */
var _ignored = Error.class;
assert error instanceof Throwable; // pass
assert typeError instanceof Throwable; // fail
Even though an Error is a Throwable, it doesn't declare its methods
var _ignored = Error.class;
Throwable error = null;
/** @j2sNative error = new Clazz.Error(); */
if (error instanceof Throwable)
error.getMessage(); // TypeError: error.getMessage$ is not a function
Expectations:
- an
Error should consistently be, or not be a Throwable
- if an
Error is a Throwable, then all its subclasses also should be and vice versa
- if an
Error is a Throwable, then it should also have all the methods declared by the Throwable
Javascript's native
Errorobjects are not instances ofjava.lang.Throwablewhich can be verified with the following codeHowever, loading
java.lang.Errorclass beforeinstanceof Throwableis invoked for the first time causes consecutive instance checks to be trueAdditionally, if the instance test was performed at least once, loading the
java.lang.Errorclass has no effectThe relation is non-transitive for subclasses of Error i.e. TypeError is Error and Error is Throwable, but TypeError is not Throwable
Even though an
Erroris aThrowable, it doesn't declare its methodsExpectations:
Errorshould consistently be, or not be aThrowableErroris aThrowable, then all its subclasses also should be and vice versaErroris aThrowable, then it should also have all the methods declared by theThrowable