More actions
Line 3: | Line 3: | ||
__NOTOC__ | __NOTOC__ | ||
An exception is an error occurs in the runtime (the excution) of program. The CGScript | 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. | ||
== <span style="color:#a52a2a;">'''Syntax'''</span> == | == <span style="color:#a52a2a;">'''Syntax'''</span> == | ||
Line 11: | Line 11: | ||
// codes that could throw an exception | // codes that could throw an exception | ||
} | } | ||
catch (exception | catch (exception) { | ||
// codes that execute when exception-declaration is thrown in the try block | // codes that execute when exception-declaration is thrown in the try block | ||
} | } | ||
[catch (exception | [catch (exception) { | ||
// code that handles another exception type | // code that handles another exception type | ||
} ] . . . ] | } ] . . . ] | ||
</pre> | </pre> | ||
* The Parameter exeption can be any types (E.g. Number type, Array type, String type...) | |||
=== throw expression === | === throw expression === | ||
throw [ | throw [value] | ||
* The '''value''' can be any types (E.g. Number type, Array type, String type...) | |||
* If throw is used without the '''value''', it will be re-throw. | |||
== <span style="color:#a52a2a;">'''Examples'''</span> == | == <span style="color:#a52a2a;">'''Examples'''</span> == |
Revision as of 10:58, 19 December 2011
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 [value]
- The value can be any types (E.g. Number type, Array type, String type...)
- If throw is used without the value, it will be re-throw.