Handling Errors

This topic describes how to handle AVBlocks errors.

When a class method encounters an error during its execution, the method returns false, and an ErrorInfo objects is generated. You can get the ErrorInfo object from the Error property of the corresponding class, for example MediaInfo.Error or Transcoder.Error.

The following example shows how you might handle an error if the MediaInfo.Load method did not succeed:

using (MediaInfo info = new MediaInfo())
{
    info.InputFile = args[0];

    if (info.Load())
    {
        PrintStreams(info);
    }
    else
    {
        PrintError(info.Error);
    }
}

The ErrorInfo.Facility, ErrorInfo.Code, and the ErrorInfo.Message properties return the component in which the error happened, the error code, and the error message. In addition for most errors the ErrorInfo.Hint property may provide additional useful information.

The following example shows how you can use the ErrorInfo object:

static void PrintError(ErrorInfo e)
{
    if (ErrorFacility.Success == e.Facility)
    {
        Console.WriteLine("Success");
    }
    else
    {
        Console.WriteLine("{0}, {1} ({2}) ({3})", 
                            e.Facility, e.Code, e.Message ?? "", e.Hint ?? "");
    }
    Console.WriteLine();
}


Last updated on November 28th, 2017 02:38:41 PM