Toggle menu
862
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Exception Handling

From Catglobe Wiki

Exception Handling (Error Runtime Handling)


An exception is an error occurs in the runtime (the excution) of program. The CGScript language uses the try/catch statement and the throw expression to implement the exception handling.

Syntax

try-catch statement

try {
   // codes that could throw an exception
}
catch (exception) {
   // codes that execute when exception-declaration is thrown in the try block
}
[catch (exception) {
   // code that handles another exception type
} ] . . . ]
  • The Parameter exeption can be any types (E.g. Number type, Array type, String type...)

throw expression

throw [expression]
  • The expression can be any types (E.g. Number type, Array type, String type...)
  • If throw is used without the expression, it will be re-throw.

Examples