Created
January 14, 2015 04:40
-
-
Save fkmhrk/c6f5af2763a0e1397e71 to your computer and use it in GitHub Desktop.
TypeScript try-catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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