HtmlWindow.Error Event

Definition

Occurs when script running inside of the window encounters a run-time error.

C#
public event System.Windows.Forms.HtmlElementErrorEventHandler Error;
C#
public event System.Windows.Forms.HtmlElementErrorEventHandler? Error;

Event Type

Examples

The following code example traps the error that results when a script on an HTML page attempts to access an object that is not defined in the document. The page must be fully loaded before the Error event handler is attached, otherwise the example will not work.

C#
private void SuppressScriptErrors()
{
    if (webBrowser1.Document != null)
    {
        webBrowser1.Document.Window.Error += new HtmlElementErrorEventHandler(scriptWindow_Error);
    }
}

private void  scriptWindow_Error(object sender, HtmlElementErrorEventArgs e)
{
    MessageBox.Show("Suppressed error!");
    e.Handled = true;
}

Remarks

HTML pages can contain script code, usually written in JScript or VBScript, that executes when a page is loaded. Error occurs whenever a script encounters a run-time error. Because script code is late-bound, which means that calls against the object are not resolved until run-time, errors can include everything from referencing a null object to calling an undefined property or method.

You can set the Handled property of HtmlElementErrorEventArgs to true in order to prevent the native error dialog box in Internet Explorer from displaying.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also