print("Throwing JS Exception");
try {
throw 'Thrown JS exception';
print("\tNo exception caught\n");
} catch (e) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Triggering Java ClassNotFoundException");
try {
str = java.lang.Class.forName("blah");
print("\tNo exception caught: " + str + "\n");
} catch (e) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing string: Packages.Test.doit(this, throw 'foo';)");
try {
str = Packages.Test.doit(this, "throw 'foo';");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing number: Packages.Test.doit(this, throw 42;)");
try {
str = Packages.Test.doit(this, "throw 42;");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing number: Packages.Test.doit(this, throw 4.2;)");
try {
str = Packages.Test.doit(this, "throw 4.2;");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing boolean: Packages.Test.doit(this, throw false;)");
try {
str = Packages.Test.doit(this, "throw false;");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing Object (new Date): Packages.Test.doit(this, throw new Date();)");
try {
str = Packages.Test.doit(this, "throw new Date();");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing Object (new String): Packages.Test.doit(this, throw new String();)");
try {
str = Packages.Test.doit(this, "throw new String();");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing Object ({a:42}): Packages.Test.doit(this, throw {a:42};)");
try {
str = Packages.Test.doit(this, "throw {a:42};");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught: " + e.toString());
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing undefined: Packages.Test.doit(this, throw undefined)");
try {
str = Packages.Test.doit(this, "throw undefined;");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught.");
print("\tJS Type of exception: " + typeof e + "\n");
}
print("Throwing null: Packages.Test.doit(this, throw null)");
try {
str = Packages.Test.doit(this, "throw null;");
print("\tNo exception caught: " + str + "\n");
} catch ( e ) {
print("\tException caught.");
print("\tType of exception: " + typeof e);
}
|
[user@machine liveconnect]$ Linux_All_DBG.OBJ/jsj test.js
Throwing JS Exception
Exception caught: Thrown JS exception
JS Type of exception: string
Triggering Java ClassNotFoundException
Exception caught: java.lang.ClassNotFoundException: blah
JS Type of exception: object
Throwing string: Packages.Test.doit(this, throw 'foo';)
Exception caught: foo
JS Type of exception: string
Throwing number: Packages.Test.doit(this, throw 42;)
Exception caught: 42
JS Type of exception: number
Throwing number: Packages.Test.doit(this, throw 4.2;)
Exception caught: 4.2
JS Type of exception: number
Throwing boolean: Packages.Test.doit(this, throw false;)
Exception caught: false
JS Type of exception: boolean
Throwing Object (new Date): Packages.Test.doit(this, throw new Date();)
Exception caught: Mon Dec 07 10:09:05 GMT-0500 (EST) 1998
JS Type of exception: object
Throwing Object (new String): Packages.Test.doit(this, throw new String();)
Exception caught:
JS Type of exception: object
Throwing Object ({a:42}): Packages.Test.doit(this, throw {a:42};)
Exception caught: [object Object]
JS Type of exception: object
Throwing undefined: Packages.Test.doit(this, throw undefined)
Exception caught.
JS Type of exception: undefined
Throwing null: Packages.Test.doit(this, throw null)
Exception caught.
Type of exception: object
[user@machine liveconnect]$
|