Skip to content

Instantly share code, notes, and snippets.

@xjamundx
Created June 4, 2011 22:16
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 xjamundx/1008418 to your computer and use it in GitHub Desktop.
Save xjamundx/1008418 to your computer and use it in GitHub Desktop.
error catching in js
function doStuff(cb) {
var badJSON = "asdlfihsdofy893q4fuiH:asdfh98#@!!!";
var bad = JSON.parse(badJSON)
console.log("bad", bad)
cb(bad)
}
try{
doStuff(function(str) {
console.log("hi", str)
})
} catch(e) {
console.log("Error:", e.message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment