Last active
December 16, 2021 07:18
-
-
Save hatemhosny/e3691dbbc210fb32d744880483ba6ea8 to your computer and use it in GitHub Desktop.
Exception Handling
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
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