Throwing exceptions in script extensions
Hi,
I am learning to write a script extension in JScript. And I can't figure out how to throw an exception in the extension, and catch it in TestComplete. For example the following code in the script extension:
function GetError(){
throw new Error("Something went wrong"); }
When I call this code in TestComplete:
function TestExtension(){ try{ MyExtension.GetError(); } catch(error){ //Do something with the error } }
I expected error.description to return "Something went wrong". However, the error object I am getting is an empty object with no properties or methods at all.
Can anyone help me get this working?
I have read this article: http://support.smartbear.com/viewarticle/57510/
I am not really fond of using Log.Error instead because it may trigger the OnLogError event handler when you don't want to.
I also dislike using the "last_status" approach. I want my code to fail when I get an uncaught exception in my code, not silently continue when I forget to add a status code check for every function call.
Regards,
Kevin
There is a restriction with passing exceptions across units:
In TestComplete, if a script calls an object method that is declared in another unit, and this method throws an exception, the exception cannot be caught and handled by the
try {}
block in the main script. Keep this in mind when developing object-oriented test scripts using native JScript functionality.mentioned in this article Supported Scripting Languages - Specifics of Usage