paul_grizzaffi
11 years agoOccasional Contributor
Can't catch Error thrown from a method in a different file
Hello,
Using JScript, I'm throwing an Error from a method (i.e. function on an object) ; the call to this method and the try/catch are in a different file. When the Error is thrown, it is not caught by the try/catch, instead it behaves like an unhandled Error and opens a TestComplete "Microsoft JScript Runtime Error" dialog.
Interesting to note, the code DOES catch the Error if all code resides in the same file.
Am I going about this correctly? Is this a limitation/bug/etc. I need to work around? Any guidance is appreciated.
Code is below.
Thanks!!!!
Paul
------
This code lives in file named MyScript:
//USEUNIT MyOtherFile
function main() {
try {
Obj.thisMethodThrows();
} catch (e) {
Log.Message("caught my error");
}
}
This code lives in file named MyOtherFile:
Obj = {
thisMethodThrows: function() {
throw new Error("here's an error");
}
}
Using JScript, I'm throwing an Error from a method (i.e. function on an object) ; the call to this method and the try/catch are in a different file. When the Error is thrown, it is not caught by the try/catch, instead it behaves like an unhandled Error and opens a TestComplete "Microsoft JScript Runtime Error" dialog.
Interesting to note, the code DOES catch the Error if all code resides in the same file.
Am I going about this correctly? Is this a limitation/bug/etc. I need to work around? Any guidance is appreciated.
Code is below.
Thanks!!!!
Paul
------
This code lives in file named MyScript:
//USEUNIT MyOtherFile
function main() {
try {
Obj.thisMethodThrows();
} catch (e) {
Log.Message("caught my error");
}
}
This code lives in file named MyOtherFile:
Obj = {
thisMethodThrows: function() {
throw new Error("here's an error");
}
}