Difference between revisions of "Exception Handling"
(→throw expression) |
(→Syntax) |
||
Line 19: | Line 19: | ||
</pre> | </pre> | ||
− | * The | + | * The '''exception''' can be any objects (E.g. Exception object, Number object, Array object, String object...) |
=== throw expression === | === throw expression === | ||
throw [expression] | throw [expression] | ||
− | * The '''expression''' can be any | + | * The '''expression''' can be any objects (E.g. Exception object, Number object, Array object, String object...) |
* If throw is used without the '''expression''', it will be re-throw. | * If throw is used without the '''expression''', it will be re-throw. | ||
== <span style="color:#a52a2a;">'''Examples'''</span> == | == <span style="color:#a52a2a;">'''Examples'''</span> == |
Revision as of 12:23, 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 exception can be any objects (E.g. Exception object, Number object, Array object, String object...)
throw expression
throw [expression]
- The expression can be any objects (E.g. Exception object, Number object, Array object, String object...)
- If throw is used without the expression, it will be re-throw.