Exceptions
You are here :

Sub nodes

Recent changes
Site plan
 
 

Exceptions obeys the same rules as in Java :

Try syntax :

 try {
   // block that may throw
 }
 [
   (
   catch (TypeName varName)
   {
     // catch block
   }
   )*
 ]
 [
   finally {
     // finally block
   }
 ]

Catch statement specify which class (and all its derived class) to catch. Therefore it is important to define the catch block in the proper order, otherwise one catch block will shadow another one. Finally statement is a block that will be executed in all cases (in the normal code execution path as well as when an exception is thrown). Of course when a try statement is defined there must be at least one catch block or one finally statement, or both or several ...

Example :

 import net.nosica.io.Console;
 class SomeClass {
   public sub f() throws Exception {
     throw new Exception("!");
   }
   public sub g() {
     try {
       f();
     }
     catch (Exception e) {
       Console.out << "Caught exceptionn";
     }
   }
 }
Propulsed by Wiclear