Поделиться через


ErrorEventArgs

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides data for the OnError event.

Syntax Notes

ErrorEventArgs is obtained as input for your own OnError event handler.

Managed Equivalent

None

Remarks

ErrorEventArgs is the base error event argument object for Silverlight in the JavaScript API. The ParserErrorEventArgs and RuntimeErrorEventArgs object both inherit from ErrorEventArgs and contain all of its properties in addition to the properties they define themselves.

Example

The following JavaScript example shows how to create an OnError event handler that displays specific error information that pertains to the type of error. The ErrorType property on the ErrorEventArgs determines the type of error.

function OnErrorEventHandler(sender, errorArgs)
{
    // Create the error message to display.
    var errorMsg = "Silverlight Error: \n\n";
    
    // Specify error information common to all errors.
    errorMsg += "Error Type:    " + errorArgs.errorType + "\n";
    errorMsg += "Error Message: " + errorArgs.errorMessage + "\n";
    errorMsg += "Error Code:    " + errorArgs.errorCode + "\n";
    
    // Determine the type of error and add specific error information.
    switch(errorArgs.errorType)
    {
        case "RuntimeError":
            // Display properties specific to RuntimeErrorEventArgs.
            if (errorArgs.lineNumber != 0)
            {
                errorMsg += "Line: " + errorArgs.lineNumber + "\n";
                errorMsg += "Position: " +  errorArgs.charPosition + "\n";
            }
            errorMsg += "MethodName: " + errorArgs.methodName + "\n";
            break;
        case "ParserError":
            // Display properties specific to ParserErrorEventArgs.
            errorMsg += "Xaml File:      " + errorArgs.xamlFile      + "\n";
            errorMsg += "Xml Element:    " + errorArgs.xmlElement    + "\n";
            errorMsg += "Xml Attribute:  " + errorArgs.xmlAttribute  + "\n";
            errorMsg += "Line:           " + errorArgs.lineNumber    + "\n";
            errorMsg += "Position:       " + errorArgs.charPosition  + "\n";
            break;
        default:
            break;
    }
    // Display the error message.
    alert(errorMsg);
}