Do uncatchable exceptions exist in Javascript?

后端 未结 2 2245
北海茫月
北海茫月 2021-02-19 23:12

Do any javascript runtimes (browsers, Node, etc.) ever throw uncatchable exceptions? Are any and all exceptions ever encountered in a javascript environment catchable in a try/c

2条回答
  •  长发绾君心
    2021-02-20 00:05

    To generalize the other answer - exceptions that are asynchronous are generally are impossible to handle without the "bug guns" designed especially to handle them - that is domains and the process "uncaughtException" event in node and onerror in the browser.

    The simplest way to get such an error would be:

    setTimeout(function(){
        throw "Catch me if you can!";
    });
    

    This is what you're seeing in the http.get({host:host, port:80}, console.error); in the example of the other answer.

提交回复
热议问题