-
Notifications
You must be signed in to change notification settings - Fork 35
Error Handling
Jing Lu edited this page Jun 17, 2013
·
34 revisions
Standard ECMAScript try/catch/finally/throw are supported by ReoScript.
Any errors could be caught using try catch syntax:
try {
// calling non-existent function causes a run-time error
undefinedfunc();
} catch(e) {
// e is instance of Error function
alert(e.message);
}
Does not matter what result about try block, the finally block always be executed.
allocMemory();
try {
// do something and error here
undefinedfunc();
} catch(e) {
console.log(e);
} finally {
releaseMemory();
}
You may throw a customize error with message.
try {
if (true) {
throw new Error('error anyway');
}
} catch(e) {
alert(e.message) // 'error anyway'
}
Errors could be thrown again, or with new one instead of old.
try {
try {
throw 'inner error';
} catch(e) {
if(e == 'inner error') {
throw 'outer error';
}
}
} catch(e) {
// e is 'outer error'
}