Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when there is a javascript runtime error?

I understand what causes runtime errors. I want to understand how the browser behaves afterwards.

Will event handlers attached before the error still work?

If a script loaded async finishes after a runtime error will it be able to execute?

Basically, how catastrophic is a run-time error?

like image 520
spinners Avatar asked Mar 16 '23 14:03

spinners


2 Answers

An uncaught runtime error only stops the current execution, which may be

  • the execution of a script
  • the call of an event handler

Suppose you have a runtime error while handling an event, the only problem you might have (apart not really handling the event) is a non consistent state of your user variables if your event handler modifies some of them. Other event handlers won't be impacted besides that.

So it can usually be considered as non catastrophic (I guess I don't have to remember it's a good practice to fix errors anyways and that flooding the console with errors isn't a good thing).

like image 178
Denys Séguret Avatar answered Mar 19 '23 18:03

Denys Séguret


You can use the try/catch/finally block. Using the catch block you can navigate inside the error and it will be running when a run-time error occurred or an illegal operation occurs. Visit this link, here is some more information about try/catch/finally http://www.javascriptkit.com/javatutors/trycatch.shtml

A run-time error can be catastrophic depends on where it happened and what does the piece of code when it occurs. In this way you can crash all the application or just stop some plugin.

like image 23
gaperaltav Avatar answered Mar 19 '23 19:03

gaperaltav