All psuedocode: Java
try {
somethingThatOftenThrowsException();
}catch (Exception e){
System.out.println("lets handle this exception: " + e);
} finally {
System.out.println("Finally block is executed either way");
}
System.out.println("Anything after the try catch is executed either
way because the control flow continues after the exception is handled. ");
Javascript
fetch("http://SomeNonExistentAPI.com")
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('something in the fetch failed: ', error));
.finally( ()=> console.log("the fetch promise is resolved one way or another"))
console.log(`this code separate and apart from the promise,
should still run or not? the exception is handled and the promise is over`);
The goal here is to have the .catch() catch the exception and keep the control flowing. That's the general concept of exception handling in my mind. You don't stop the whole program over one error. Javascript seems to stop after the finally.
TLDR: In Javascript, how do I get the program to keep running after an error is caught and handled?