Created
September 13, 2017 17:51
-
-
Save duaneleem/05695c531485d09fcea95db2f7efb576 to your computer and use it in GitHub Desktop.
Try/Catch example.
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
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