Compartir a través de


AnalysisWarning.BackgroundException Property

The Exception that is thrown if an exception occurs in during background analysis of ink.

Namespace: Microsoft.Ink
Assembly: Microsoft.Ink.Analysis (in microsoft.ink.analysis.dll)

Syntax

'Declaration
Public ReadOnly Property BackgroundException As Exception
'Usage
Dim instance As AnalysisWarning
Dim value As Exception

value = instance.BackgroundException
public Exception BackgroundException { get; }
public:
property Exception^ BackgroundException {
    Exception^ get ();
}
/** @property */
public Exception get_BackgroundException ()
public function get BackgroundException () : Exception
Not applicable.

Property Value

The Exception that was thrown during background analysis.

Remarks

If an Exception occurs after a call to InkAnalyzerBase.BackgroundAnalyze, then the exception cannot be thrown because it is occurring in a different thread and there would be no way to catch it. Instead, in the ResultsUpdated event handler, the Status property of the ResultsUpdatedEventArgs object will have an AnalysisWarning object of type BackgroundException in its Warnings collection. The BackgroundException property of this AnalysisWarning object will contain the Exception that was thrown during background analysis. In general, you will want to rethrow this Exception so that it can be caught elsewhere in your application. From this point on the ink analyzer is unusable and it should be reinstantiated.

Example

The following example shows an AnalysisWarning, warning, which is checked to see if it is associated with any hints. If the AnalysisWarning is of type BackgroundException , then you should attempt to save as much document state as possible and then rethrow the exception so that it can be caught by an exception handler. Even if no exception handler is in place, then a program error debugger, such as Dr. Watson, can be invoked. The InkAnalyzer will need to be reinitialized after catching the exception.

' Loop through warnings
Dim warning As AnalysisWarning
For Each warning In status.Warnings
    Select Case warning.WarningCode
        Case Microsoft.Ink.AnalysisWarningCode.Aborted
            message = message & "Analysis operation was aborted. "
        Case Microsoft.Ink.AnalysisWarningCode.BackgroundException
            ' This is a fatal warning. Throw an exception.
            ' First, attempt to save as much document state as possible 
            ' ...

            ' Rethrow the exception so that it can be caught by an exception
            ' handler (or if there is no exception handler, a program error 
            ' debugger such as Dr. Watson can be invoked)
            Throw (warning.BackgroundException)
        Case Microsoft.Ink.AnalysisWarningCode.ConfirmedWithoutInkRecognition
            message = message & "Node was confirmed without ink recognition having been performed. "
        Case Microsoft.Ink.AnalysisWarningCode.ContextNodeLocationNotSet
            message = message & "Node does not have a proper location set. "
        Case Microsoft.Ink.AnalysisWarningCode.FactoidCoercionNotSupported
            message = message & "Factoid coercion failed "
            If (Not warning.AnalysisHint Is Nothing) AndAlso (Not warning.AnalysisHint.Factoid Is Nothing) Then
                message = message & "for factoid: " & warning.AnalysisHint.Factoid & ". "
            End If
        Case Microsoft.Ink.AnalysisWarningCode.FactoidNotSupported
            If (Not warning.AnalysisHint Is Nothing) AndAlso (Not warning.AnalysisHint.Factoid Is Nothing) Then
                message = message & warning.AnalysisHint.Factoid & " factoid was not respected. "
            End If
        Case Microsoft.Ink.AnalysisWarningCode.GuideNotSupported
            message = message & "Guide was not respected. "
        Case Microsoft.Ink.AnalysisWarningCode.AddInkToRecognizerFailed
            message = message & "Ink could not be added to the InkRecognizer. "
        Case Microsoft.Ink.AnalysisWarningCode.InkRecognizerInitializationFailed
            message = message & "The InkRecognizer failed to initialize. "
        Case Microsoft.Ink.AnalysisWarningCode.NoMatchingInkRecognizerFound
            message = message & "There are no ink recognizers meeting the language or capabilities needed. "
        Case Microsoft.Ink.AnalysisWarningCode.LanguageIdNotRespected
            message = message & "The language ID set on a stroke did not match the language ID of the InkRecognizer. "
        Case Microsoft.Ink.AnalysisWarningCode.PartialDictionaryTermsNotSupported
            message = message & "Partial dictionary terms could not be returned from the text recognizer. "
        Case Microsoft.Ink.AnalysisWarningCode.TextRecognitionProcessFailed
            message = message & "The text recognition process failed. "
        Case Microsoft.Ink.AnalysisWarningCode.SetPrefixSuffixFailed
            message = message & "The text recognizer was unable to respect either the prefix or suffix. "
            If (Not warning.AnalysisHint Is Nothing) AndAlso (Not warning.AnalysisHint.PrefixText Is Nothing) Then
                message = message & "Prefix: " & warning.AnalysisHint.PrefixText & ". "
            End If
            If (Not warning.AnalysisHint Is Nothing) AndAlso (Not warning.AnalysisHint.SuffixText Is Nothing) Then
                message = message & "Suffix: " & warning.AnalysisHint.SuffixText & ". "
            End If
        Case Microsoft.Ink.AnalysisWarningCode.WordlistNotSupported
            message = message & "Wordlist was not respected. "
        Case Microsoft.Ink.AnalysisWarningCode.WordModeNotSupported
            message = message & "Word mode was not respected. "
    End Select


    ' Add node id information
    Dim id As Guid
    For Each id In warning.GetNodeIds()
        message = message & "Id: " & id.ToString() & " "
    Next id


    ' Add hint information
    If Not (warning.AnalysisHint Is Nothing) Then
        Dim hint As AnalysisHintNode = warning.AnalysisHint
        message = message & Environment.NewLine & "Hint information: "
        message = message & "AllowPartialDictionaryTerms"
        If hint.AllowPartialDictionaryTerms = True Then
            message = message & " = True "
        Else
            message = message & " = False "
        End If
        message = message & "CoerceToFactoid"
        If hint.CoerceToFactoid = True Then
            message = message & " = True "
        Else
            message = message & " = False "
        End If
        If Not hint.Factoid Is Nothing Then
            message = message & "Factoid = " & warning.AnalysisHint.Factoid & " "
        End If
        If hint.Guide.DrawnBox <> Rectangle.Empty Then
            message = message & "Guide Drawn Box = " & hint.Guide.DrawnBox.ToString()
        End If
        If hint.Guide.WritingBox <> Rectangle.Empty Then
            message = message & "Guide Writing Box = " & hint.Guide.WritingBox.ToString()
        End If
        message = message & String.Format("Guide = ({0}, {1})", _
             hint.Guide.Columns, hint.Guide.Rows)
        If Not hint.Name Is Nothing Then
            message = message & "Name = " & warning.AnalysisHint.Name & " "
        End If
        If Not hint.PrefixText Is Nothing Then
            message = message & "PrefixText = " & warning.AnalysisHint.PrefixText & " "
        End If
        If Not hint.SuffixText Is Nothing Then
            message = message & "SuffixText = " & warning.AnalysisHint.SuffixText & " "
        End If
        message = message & "WordMode"
        If hint.WordMode = True Then
            message = message & " = True"
        Else
            message = message & " = False"
        End If
    End If

    message = message & Environment.NewLine
Next warning
// Loop through warnings
foreach (AnalysisWarning warning in status.Warnings)
{
    switch (warning.WarningCode)
    {
        case Microsoft.Ink.AnalysisWarningCode.Aborted:
            message += "Analysis operation was aborted. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.BackgroundException:
            // This is a fatal warning. Throw an exception.
            // First, attempt to save as much doc state as possible 
            // ...

            // Rethrow the exception so that it can be caught by an exception
            // handler (or if there is no exception handler, a program error 
            // debugger such as Dr. Watson can be invoked)
            throw(warning.BackgroundException);
        case Microsoft.Ink.AnalysisWarningCode.ConfirmedWithoutInkRecognition:
            message += "Node was confirmed without ink recognition having been performed. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.ContextNodeLocationNotSet:
            message += "Node does not have a proper location set. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.FactoidCoercionNotSupported:
            message += "Factoid coercion failed ";
            if (warning.AnalysisHint != null && warning.AnalysisHint.Factoid != null)
            {
                message += "for factoid: " + warning.AnalysisHint.Factoid + ". ";
            } 
            break;
        case Microsoft.Ink.AnalysisWarningCode.FactoidNotSupported:
            if (warning.AnalysisHint != null && warning.AnalysisHint.Factoid != null)
            {
                message += warning.AnalysisHint.Factoid + " factoid was not respected. ";
            }
            break;
        case Microsoft.Ink.AnalysisWarningCode.GuideNotSupported:
            message += "Guide was not respected. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.AddInkToRecognizerFailed:
            message += "Ink could not be added to the InkRecognizer. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.InkRecognizerInitializationFailed:
            message += "The InkRecognizer failed to initialize. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.NoMatchingInkRecognizerFound:
            message += "There are no ink recognizers meeting the language or capabilities needed. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.LanguageIdNotRespected:
            message += "The language ID set on a stroke did not match the language ID of the InkRecognizer. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.PartialDictionaryTermsNotSupported:
            message += "Partial dictionary terms could not be returned from the text recognizer. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.TextRecognitionProcessFailed:
            message += "The text recognition process failed. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.SetPrefixSuffixFailed:
            message += "The text recognizer was unable to respect either the prefix or suffix. ";
            if (warning.AnalysisHint != null && warning.AnalysisHint.PrefixText != null)
            {
                message += "Prefix: " + warning.AnalysisHint.PrefixText + ". ";
            }
            if (warning.AnalysisHint != null && warning.AnalysisHint.SuffixText != null)
            {
                message += "Suffix: " + warning.AnalysisHint.SuffixText + ". ";
            }
            break;
        case Microsoft.Ink.AnalysisWarningCode.WordlistNotSupported:
            message += "Wordlist was not respected. ";
            break;
        case Microsoft.Ink.AnalysisWarningCode.WordModeNotSupported:
            message += "Word mode was not respected. ";
            break;
    }

    // Add node id information
    foreach (Guid id in warning.GetNodeIds())
        message += "Id: " + id.ToString() + " ";

    // Add hint information
    if (warning.AnalysisHint != null)
    {
        AnalysisHintNode hint = warning.AnalysisHint;
        message += Environment.NewLine + "Hint information: ";
        message += "AllowPartialDictionaryTerms";
        if (hint.AllowPartialDictionaryTerms)
            message += " = true ";
        else
            message += " = false ";
        message += "CoerceToFactoid";
        if (hint.CoerceToFactoid)
            message += " = true ";
        else
            message += " = false ";
        if (hint.Factoid != null)
            message += "Factoid = " + warning.AnalysisHint.Factoid + " ";
        if (hint.Guide.DrawnBox != Rectangle.Empty)
            message += "Guide Drawn Box = " + hint.Guide.DrawnBox.ToString();
        if (hint.Guide.WritingBox != Rectangle.Empty)
            message += "Guide Writing Box = " + hint.Guide.WritingBox.ToString();
        if (hint.Name != null)
            message += "Name = " + warning.AnalysisHint.Name + " ";
        if (hint.PrefixText != null)
            message += "PrefixText = " + warning.AnalysisHint.PrefixText + " ";
        if (hint.SuffixText != null)
            message += "SuffixText = " + warning.AnalysisHint.SuffixText + " ";
        message += "WordMode";
        if (hint.WordMode)
            message += " = true";
        else
            message += " = false";
    }
    message += Environment.NewLine;
}

Platforms

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

AnalysisWarning Class
AnalysisWarning Members
Microsoft.Ink Namespace
InkAnalyzerBase.BackgroundAnalyze