What happens when there is a javascript runtime error? - Stack Overflow

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

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?

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?

Share Improve this question asked Apr 1, 2015 at 15:22 spinnersspinners 2,7093 gold badges26 silver badges37 bronze badges 2
  • Will event handlers attached before the error still work? Try it and see! – Evan Davis Commented Apr 1, 2015 at 15:26
  • That depends on browser behavior and you have little or no control over that. If you have a runtime error do you best to resolve it, don't try to measure how bad it is or rely on current situation that maybe works now, but may not work tomorrow. A runtime error means there's a bug in the script. You need to fix it. – Lucius Commented Apr 1, 2015 at 15:31
Add a ment  | 

3 Answers 3

Reset to default 8

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).

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./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.

Whenever a webpage is opened, all the scripts starts loading. If any of the scripts encounters any runtime error, then the execution of that script stops. That means any further statements in the scripts will not get executed by the browser. You can find these errors on the console window of the browser. However you can make use of try catch blocks to handle the exceptions occuring. For example, consider the following script:

<script>
    var x=10, y=0;
    /*...............
    .................
    perform some other tasks here
    This will execute with no error
    .................
    ................*/
    var z=x/y; //here error occur
//below any statements will never execute.
{
    /*................
    ..................
    some operations
    this block will not execute because a runtime error occurs above.
    ..................
    ................*/
}
</script>

No any further statement after statement var z=x/y; will execute because a runtime error occured.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743659543a4485951.html

相关推荐

  • What happens when there is a javascript runtime error? - Stack Overflow

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

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信