Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Java Exceptions - thrown from the java code running behind SILSIL™
  2. SIL SIL™ objects thrown using throw (explained below)

...

The general syntax for throwing an exception from SIL SIL™ is:

Code Block
throw <value>;

Any SIL SIL™ value can be thrown as exception. Values can either be constants, variables or expressions.

Code Block
throw errorCode;
throw 2;
throw array[0].fieldName;
throw ("Fiend value invalid: " + structure.field);
throw "Generic error!";

 


Try-catch block

...


Code Block
titleSyntax
try {
	<instructions> 
} catch <type> <varName> {
	// handle <varName>
} catch {
	// handle other error
} 

...

If any instruction in the try block throws an exception, execution of instructions within the try block is stopped. That is, any instructions within the try block after the one that throws the exception will not be executed. 

Next, SIL SIL™ will iterate over the catch clauses in the order they were declared looking for a catch clause that matches the type of the error that was thrown:

  • Typed catch clauses will match if the <type> declared in the catch clause matches the type of the exception. That means that typed catch clauses can only catch SIL objects thrown using throw. The caught value is available inside the catch block using the defined <varname>
  • The catch all clause will catch any exception (SIL SIL™ Objects or Java exceptions) regardless of type.

If a matching catch clause was found, the instructions within the catch block are executed and the program will continue. If no matching catch clause is found, the exception is thrown inside the outer code block. This makes it possible to nest try-catch blocks within one another and throw exceptions from the inner block to be caught by the topmost one. 


Examples

...


Code Block
titleType matching
try {
	number errorCode = 2;
	throw errorCode;
} catch string s {
	// will not match
} catch number err {
	// will match because a number was thrown
    //err = 2
}

...

Code Block
titleJava Exceptions
try {
	runAs("user_that_does_not_exist");
} catch string err {
	// will not match
} catch {
	// will match
}

 

 

 

 

...