Revision [808]

This is an old revision of ExceptionHandling made by DavidLee on 2009-09-30 06:10:53.

 

Exception Handling


xmlsh supports the Java style syntax for exception handling. Currently the only exceptions that are supported are the exceptions generated by the throw command. Native java exceptions generated within command are trapped at the completion of that command, printed on stderr, and converted to a -1 exit status.

The syntax for a try/catch block is as follows
try { list ; } catch word { list ; }
try { list ; } catch word { list ; } finally { list ; }

If the finally clause is used it MUST be on the same line as the closing brace for the catch clause.
In order to raise an exception the throw command must be used
throw expression

The expression can be any type and it is passed to the catch clause as the value of the variable "word".

Examples
try {
	if !  command ; then
		throw "Failed command" 
	fi
	command2 ;
	
}  
catch X 
{
	echo Error: $X
	
}  finally 
{
	echo Completed block
}



[CategoryCommands]
BasicSyntax
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki