Skip to content
Jing Lu edited this page May 14, 2013 · 34 revisions

Standard ECMAScript try/catch/finally/throw are supported by ReoScript.

Catch Error

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);
}

Finally

Does matter what the try block is passed, the finally block always be executed.

allocMemory();

try {
  // do something and error here
  undefinedfunc();
} catch(e) {
  console.log(e);
} finally {
  releaseMemory();
}

Custom Error

try {
  if (true) {
    throw new Error('error anyway');
  }
} catch(e) {
  alert(e.message)     // 'error anyway'
}

Nested Try Catch

try {
  try {
    throw 'inner error';
  } catch(e) {
    if(e == 'inner error') {
      throw 'outer error';
    }
  }
} catch(e) {
  // e is 'outer error'
}

Clone this wiki locally