Skip to content

Instantly share code, notes, and snippets.

@fkmhrk
Created January 14, 2015 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fkmhrk/c6f5af2763a0e1397e71 to your computer and use it in GitHub Desktop.
Save fkmhrk/c6f5af2763a0e1397e71 to your computer and use it in GitHub Desktop.
TypeScript try-catch
var MyException = (function () {
function MyException(status, body) {
this.status = status;
this.body = body;
}
return MyException;
})();
function moke() {
try {
throw new MyException(404, { "msg": "not found" });
}
catch (e) {
console.log(e.status);
}
}
class MyException {
status : number;
body : any;
constructor(status : number, body : any) {
this.status = status;
this.body = body;
}
}
function moke() {
try {
throw new MyException(404, {"msg":"not found"});
} catch (e) {
console.log((<MyException> e).status);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment