Skip to content

Instantly share code, notes, and snippets.

@duaneleem
Created September 13, 2017 17:51
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 duaneleem/05695c531485d09fcea95db2f7efb576 to your computer and use it in GitHub Desktop.
Save duaneleem/05695c531485d09fcea95db2f7efb576 to your computer and use it in GitHub Desktop.
Try/Catch example.
export class TryCatchExample {
mtdExample() {
try {
for (editIndex = 0; editIndex < partner.objProjects.length; editIndex++)
{
if (partner.objProjects[editIndex].id == req.body.projectId) {found = true; break;}
}
if (!found)
{
return res.status(404).json({
title: "Project not found",
error: {message: "The passed ID does not match any project for this charity"}
});
}
for (updateIndex = 0; updateIndex < partner.objProjects[editIndex].objUpdates.length; updateIndex++)
{
if (partner.objProjects[editIndex].objUpdates[updateIndex].id == req.body.updateId) {updateFound = true; break;}
}
} catch(e) {
// We assume because it was the header set error.
console.log("The header was already set.");
} // try / catch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment