swig/Examples/javascript/exception/runme.js
William S Fulton 00190c484f Javascript, Octave, R - Improve exceptions for %catches
and exception specifications for native types.

Now the raised exception contains the string value as the exception
message instead of just the C/C++ type of the exception.

R exceptions were completely swallowed beforehand
2022-09-19 09:09:29 +01:00

64 lines
1.2 KiB
JavaScript

var example = require("example");
console.log("Trying to catch some exceptions.");
t = new example.Test();
try{
t.unknown();
throw -1;
} catch(error)
{
if(error == -1) {
console.log("t.unknown() didn't throw");
} else {
console.log("successfully caught throw in Test::unknown() :" + error);
}
}
try{
t.simple();
throw -1;
}
catch(error){
if(error == -1) {
console.log("t.simple() did not throw");
} else {
console.log("successfully caught throw in Test::simple() :" + error);
}
}
try{
t.message();
throw -1;
} catch(error){
if(error == -1) {
console.log("t.message() did not throw");
} else {
console.log("successfully caught throw in Test::message() :" + error);
}
}
try{
t.hosed();
throw -1;
}
catch(error){
if(error == -1) {
console.log("t.hosed() did not throw");
} else {
console.log("successfully caught throw in Test::hosed() :" + error + " " + error.code + " " + error.msg);
}
}
for (var i=1; i<4; i++) {
try{
t.multi(i);
throw -1;
}
catch(error){
if(error == -1) {
console.log("t.multi(" + i + ") did not throw");
} else {
console.log("successfully caught throw in Test::multi() :" + error);
}
}
}