<p>I'm using the <code>System.Windows.Forms.WebBrowser</code>, to make a view a-la Visual Studio Start Page. However, it seems the control is catching and handling all exceptions by silently sinking them! No need to tell this is a very unfortunate behaviour.</p>

<pre><code>void webBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
    // WebBrowser.Navigating event handler
    throw new Exception("OMG!");
}
</code></pre>

<p>The code above will cancel navigation and swallow the exception.</p>

<pre><code>void webBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
    // WebBrowser.Navigating event handler
    try
    {
        e.Cancel = true;
        if (actions.ContainsKey(e.Url.ToString()))
        {
            actions[e.Url.ToString()].Invoke(e.Url, webBrowser.Document);
        }
    }
    catch (Exception exception)
    {
        MessageBox.Show(exception.ToString());
    }
}
</code></pre>

<p>So, what I do (above) is catch all exceptions and pop a box, this is better than silently failing but still clearly far from ideal. I'd like it to redirect the exception through the normal application failure path so that it ultimately becomes unhandled, or handled by the application from the root.</p>

<p>Is there any way to tell the <code>WebBrowser</code> control to stop sinking the exceptions and just forward them the natural and expected way? Or is there some hacky way to throw an exception through native boundaries?</p>

[{'answer_id': 18138, 'author': 'Judah Gabriel Himango', 'author_id': 536, 'author_profile': 'https://Stackoverflow.com/users/536', 'pm_score': 1, 'selected': False, 'text': "<p>I haven't seen the browser eat exceptions, unless you mean script errors. Script errors can be enabled via the <code>browser.ScriptErrorsSuppressed</code> property.</p>\n\n<p>If you're talking about real exceptions, not just script errors, can you show us some code that reproduces the problem? We've used the browser extensively and haven't seen what you're describing.</p>\n\n<p><em>edit</em> the code sample wasn't there when I asked for a code sample</p>\n"}, {'answer_id': 1493026, 'author': 'Coincoin', 'author_id': 42, 'author_profile': 'https://Stackoverflow.com/users/42', 'pm_score': 1, 'selected': True, 'text': "<p>My best bet why it happens is because there is a native-managed-native boundary to cross. The native part doesn't forward the managed exceptions correctly and there is not much that can be done.</p>\n\n<p>I am still hoping for a better answer though.</p>\n"}, {'answer_id': 63057905, 'author': 'eanv', 'author_id': 13983631, 'author_profile': 'https://Stackoverflow.com/users/13983631', 'pm_score': 0, 'selected': False, 'text': '<p>11 years late to the party here, but the following solution works for me.</p>\n<p>In <code>webBrowserNavigating</code>, replace <code>MessageBox.Show(exception.ToString());</code> with <code>Dispatcher.BeginInvoke(() =&gt; { throw exception; });</code>.</p>\n<p>As soon as the <code>webBrowserNavigating</code> method completes and control returns to the windows event loop, the exception is thrown and handled by the normal mechanism.</p>\n'}]
['https://Stackoverflow.com/questions/18059', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/42/']