-2

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?

  • 2
    There is no question in your post. – aled Aug 31 '23 at 19:41
  • How do I get the program to keep running after an error is caught and handled? – Jon Billingsley Sep 01 '23 at 02:45
  • Try removing incorrect tags. The question is about Javascript. Also avoid formatting and 'TLDR' in the post. Your question should be clear by itself. Please read [How to Ask](https://stackoverflow.com/help/how-to-ask). – aled Sep 01 '23 at 11:41
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 01 '23 at 15:11

0 Answers0