Skip to content

Instantly share code, notes, and snippets.

@robrighter
Created November 1, 2013 20:16
Show Gist options
  • Save robrighter/7271319 to your computer and use it in GitHub Desktop.
Save robrighter/7271319 to your computer and use it in GitHub Desktop.
Typical error handling problem in javascript
function genericXmlParser(xml, callback){
var parser = new xml2js.Parser();
var isParseError = true;
try
{
parser.parseString(xml, function(err,obj){
isParseError = false;
if(err){
callback({error: 'XML Parsing Error'});
}
else{
callback(obj);
}
});
}
catch(e)
{
//for xml parsing error
if(isParseError){
callback({error: 'XML Parsing Error'});
}
else {
throw e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment