do ... except Statement

Action

Handles (ignores) an exception without halting a script.

Syntax

do 
statements1
except
statements2
Variable Description
statements1 A single statement or series of statements that may generate an exception.
statements2 A single statement or series of statements (executed only if exception is raised in statements1).

Example

[-] TestVerification (STRING sExpectedValue, STRING sTestValue)
	[-] if ( sExpectedValue == sTestValue )
		[ ] Print ("Test was successful") 
	[-] else 
		[ ] raise 1, "ERROR: Test verification failed" 
	[ ] return 
	[ ] 
	[ ] 
[-] ErrorHandler () 
	[ ] Print (ExceptData()) 
	[ ] // This script prints: 
	[ ] // ERROR: Test verification failed 
	[ ] return 
	[ ] 
	[ ] 
[-] testcase do_except_example () 
	[ ] STRING sTestValue = "xxx" 
	[ ] STRING sExpectedValue = "yyy"
	[-] do 
		[ ] TestVerification (sExpectedValue, sTestValue) 
	[-] except 
		[ ] ErrorHandler () 
	[ ] // Continue with testcase 
	[ ] ...

Notes

  • The do...except statement allows a possible exception to be handled by the test case instead of automatically terminating the test case. If an exception is raised while the do clause (statements1) has control of the script, control immediately jumps to the first statement in statements2 in the except clause, which often is a call to one of the built-in 4Test functions that gets information on exceptions.

  • If no exception is raised while statements1 has control of the script, control jumps to the first statement beyond the do ... except statement. The statements in statements2 are not executed.