Difference between revisions of "Exception Handling"
(→Exception Handling (Error Runtime Handling)) |
(→try-catch statement) |
||
Line 12: | Line 12: | ||
} | } | ||
catch (exception) { | catch (exception) { | ||
− | // codes that execute when exception | + | // codes that execute when exception is thrown in the try block |
} | } | ||
</pre> | </pre> | ||
+ | * In the try clause, when a line of code cause the exception/error, the exception will be thrown to the catch clause and the codes in catch clause will process that exception. All codes below the code which cause the exception/error will be ignored. | ||
* The '''exception''' can be any type (E.g. exception object, number, string...) | * The '''exception''' can be any type (E.g. exception object, number, string...) | ||
* CGScript language does not support multi catch clauses. | * CGScript language does not support multi catch clauses. |
Revision as of 04:57, 20 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 is thrown in the try block }
- In the try clause, when a line of code cause the exception/error, the exception will be thrown to the catch clause and the codes in catch clause will process that exception. All codes below the code which cause the exception/error will be ignored.
- The exception can be any type (E.g. exception object, number, string...)
- CGScript language does not support multi catch clauses.
throw expression
throw [expression]
- The expression can be any type (E.g. exception object, number, string...)
- If throw is used in catch clause, it will be re-throw. See below examples for information about re-throw.