<!DOCTYPE html>
<html>
  <body>
    <script src="script.js"></script>
    <script>
     document.body.innerHTML += "Starting...<br>";
     var my = new MyClass();
     my.foo(null, { answer: 42 });
     document.body.innerHTML += "<br>Continue execution...";
    </script>
  </body>
</html>
class MyClass {
	
	@safe public foo(str: string, data: any): boolean {
    return str.length > 0;
  }
}

function safe(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> {
  var originalMethod = descriptor.value;
  descriptor.value = function NoErrorWrapper () {
    try {
      originalMethod.apply(this, arguments);
    } catch(ex) {
      var message = ex.name + " occured in call of " + 
          target.constructor.name + "." + propertyKey + ": " + ex.message + "\n";
      message += "Arguments:\n";
      [].forEach.call(arguments, (x, i) => 
         message += "   [" + i + "]: " + JSON.stringify(x) + " \n");
      message += "Callstack:" + ex.stack;
      console.error(message);
      document.body.innerHTML += "<br><pre style='color: red'>" + message + "</pre>";
    }
  };
  return descriptor;
}
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}