swig/Examples/javascript/exception/runme.js
2013-09-03 06:26:54 +02:00

64 lines
1.2 KiB
JavaScript

var example = require("./build/Release/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 catched throw in Test::unknown().");
}
}
try{
t.simple();
throw -1;
}
catch(error){
if(error == -1) {
console.log("t.simple() did not throw");
} else {
console.log("successfully catched throw in Test::simple().");
}
}
try{
t.message();
throw -1;
} catch(error){
if(error == -1) {
console.log("t.message() did not throw");
} else {
console.log("successfully catched throw in Test::message().");
}
}
try{
t.hosed();
throw -1;
}
catch(error){
if(error == -1) {
console.log("t.hosed() did not throw");
} else {
console.log("successfully catched throw in Test::hosed().");
}
}
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 catched throw in Test::multi().");
}
}
}