I'm using the System.Windows.Forms.WebBrowser, 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.
void webBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
// WebBrowser.Navigating event handler
throw new Exception("OMG!");
}
The code above will cancel navigation and swallow the exception.
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());
}
}
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.
Is there any way to tell the WebBrowser 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?