Forum Discussion
Ameett,
To handle exceptions in JScript, use the try... catch blocks:
function demo()
{
var a=2;
var b=3;
try
{
d=c+a+b;
}
catch(e)
{
// Handle exception
Log.Message("Error: " + e.name, e.description);
}
}
The try... catch statement works only for scripting errors. It will not help if an error occurs in a call to a method or property of a test object, for instance, if a click on a button fails. In this case, the method of the property will not raise an exception, but will post an error message to the test log.
By default, this error message will also cause your test to stop. This happens, because by default, the Stop on error property of your project is enabled. When this property is enabled, TestComplete stops the test run when it detects an error message posted to the log.
To disable the property, right-click your project in the Project Explorer panel and select Edit | Properties from the context menu. This will invoke the project editor and activate its Properties page. Select the Playback category from the tree on the left. You will see the Stop on error property on the right.
The Stop on error property used alone (without try…catch) will not protect you from stopping on script exceptions as the script engine cannot work after an unhandled exception occurs.
Related Content
- 5 years ago
- 14 years ago
- 6 years ago
Recent Discussions
- 10 hours ago