{"id":2676,"date":"2022-08-30T15:26:51","date_gmt":"2022-08-30T15:26:51","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/06\/how-do-i-keep-the-webbrowser-control-from-catching-exceptions-and-displaying-them-as-script-errors-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:51","modified_gmt":"2022-08-30T15:26:51","slug":"how-do-i-keep-the-webbrowser-control-from-catching-exceptions-and-displaying-them-as-script-errors-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-do-i-keep-the-webbrowser-control-from-catching-exceptions-and-displaying-them-as-script-errors-collection-of-common-programming-errors\/","title":{"rendered":"How do I keep the WebBrowser control from catching exceptions and displaying them as script errors?-Collection of common programming errors"},"content":{"rendered":"<p>I didn&#8217;t end up with a universal solution, but this one works well enough for me.<\/p>\n<p>Communication between the browser and my application is only done through a single Javascript method. So I just wrapped all of the code in that method in a try\/catch block and threw the exception on another thread.<\/p>\n<pre><code>[ComVisible(true)]\npublic class JavascriptBridge {\n    public void Notify(string data) {\n        try {\n            \/\/ Process the data\n        } catch (Exception ex) {\n            System.Threading.ThreadPool.QueueUserWorkItem((state) =&gt; {\n                throw new Exception(\"An unhandled exception ocurred while servicing a Javascript method call.\", ex);\n            });\n        }\n    }\n}\n<\/code><\/pre>\n<p>This completely bypasses the browser control&#8217;s exception handler and retains the original exception&#8217;s location information. Note, however, that the only way to catch the exception again is with the <code>Application.ThreadException<\/code> event.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-02-06 03:18:06. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I didn&#8217;t end up with a universal solution, but this one works well enough for me. Communication between the browser and my application is only done through a single Javascript method. So I just wrapped all of the code in that method in a try\/catch block and threw the exception on another thread. [ComVisible(true)] public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2676","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2676"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2676\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}