如何重写或冒泡javascript try/catch块?

时间:2022-10-30 11:56:47

I have an application that uses a few external libraries. These libraries use try/catch blocks to deal with errors. Rather then editing the libraries and removing the try/catch blocks is there a way to force them to bubble up to a function I control so that I can post them to my server?

我有一个应用程序,它使用一些外部库。这些库使用try/catch块来处理错误。相反,编辑这些库并删除try/catch块,是否有办法迫使它们冒泡到一个我控制的函数中,这样我就可以将它们发布到我的服务器上?

here is an example

这是一个例子

'parseBindingsString': function(bindingsString, bindingContext, node, options) {
        try {
            var bindingFunction = createBindingsStringEvaluatorViaCache(bindingsString, this.bindingCache, options);
            return bindingFunction(bindingContext, node);
        } catch (ex) {
            ex.message = "Unable to parse bindings.\nBindings value: " + bindingsString + "\nMessage: " + ex.message;
            throw ex;
        }
    }

1 个解决方案

#1


3  

Nope. If an Exception is thrown and catched, it won't bubble up again (unless the catch blocks rethrows the exception).

不。如果一个异常被抛出并被捕获,它将不会再次冒泡(除非捕获块重新抛出异常)。

#1


3  

Nope. If an Exception is thrown and catched, it won't bubble up again (unless the catch blocks rethrows the exception).

不。如果一个异常被抛出并被捕获,它将不会再次冒泡(除非捕获块重新抛出异常)。