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

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

Catch Error

try {
  // call non-existed function should cause a run-time error
  undefinedfunc();
} catch(e) {
  // e is instance of Error function
  alert(e.message);
}

Finally

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'
}