Skip to content

Commit

Permalink
Added Async Try Catch
Browse files Browse the repository at this point in the history
  • Loading branch information
khianvictorycalderon committed Dec 6, 2024
1 parent c90c0c6 commit 4c5513e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Async_Try_Catch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This will determine if a function is sucessfully executed
const ExecutionSuccess = false; // Change this as necessary

async function ExecuteTime() {
return new Promise((resolve, reject) => {
setTimeout(() => {
if(ExecutionSuccess) {
resolve("Execution Successful!")
} else {
reject("Server Inactive"); // Sample error message
}
},1000) // Wait 1 second
});
}

async function WaitExecute() {
try {
// If the execution is successful
const result = await ExecuteTime();
console.log(result);
} catch (e) {
// If the execution is unsuccessful
console.log(`Fetch Failed: ${e}`);
} finally {
// If the execution is done whether successful or not
console.log("Execution done.")
}
}

WaitExecute();

0 comments on commit 4c5513e

Please sign in to comment.