3.6 Exception Handling: try/catch/throw

Like Java, NOC Script contains a mechanism to catch exceptions thrown by a block of code. Unlike Java, however, exceptions are not declared by type. A single catch clause catches the thrown exceptions:

try
{
   if( somethingBadHappened )
      throw 'get outta here'
}
catch( Exception )
{
    writeln( 'Exception was thrown: ' + Exception )
}

To catch a specific exception, use the following exception catch syntax:

try
{
    // Open our file.
    var f = new java.io.FileInputStream( 'somefile.txt' )
    // …
}
catch( IOException if ( IOException instanceof java.io.IOException ) )
{
    writeln( 'I/O exception was thrown: ' + IOException )
}