Skip to content

Instantly share code, notes, and snippets.

@hatemhosny
Last active December 16, 2021 07:18
Show Gist options
  • Save hatemhosny/e3691dbbc210fb32d744880483ba6ea8 to your computer and use it in GitHub Desktop.
Save hatemhosny/e3691dbbc210fb32d744880483ba6ea8 to your computer and use it in GitHub Desktop.
Exception Handling
function notify(message) {
return new Promise((resolve, reject) => {
try {
let response = NotificationService.send(message);
resolve(response);
} catch (err) {
reject(err);
}
});
}
function saveData() {
return new Promise((resolve, reject) => {
try {
let response = DB.query("insert into ...");
resolve(response);
} catch (err) {
reject(err);
}
});
}
saveData()
.then(() => notify("Data Saved"))
.then((data) => {
//do something with Right result
})
.catch((err) => {
//do something with Left error
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment