Handling Errors

This topic describes how to handle AVBlocks errors.

.NET

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();
}

C++

When a class method encounters an error during its execution, the method returns 0 (FALSE), and an ErrorInfo objects is generated. You can get the ErrorInfo object by calling the error method of the corresponding class, for example MediaInfo::error or Transcoder::error.

This example shows how you might handle an error if the MediaInfo::load method did not succeed:

MediaInfo* info = Library::createMediaInfo();

wchar_t* inputFile = argv[1];

info->setInputFile(inputFile);

if(info->load())
{
    printStreams(info);
}
else
{
    printError(info->error());
}

info->release();

The ErrorInfo::facility, ErrorInfo::code, and the ErrorInfo::message methods return the component in which the error happened, the error code, and the error message. In addition for most errors the ErrorInfo::hint method may provide additional useful information.

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

void printError(const primo::error::ErrorInfo* e)
{
    if (primo::error::ErrorFacility::Success == e->facility())
    {
        wcout << L"Success";
    }
    else
    {
        wcout << L"facility: " << e->facility() << L", error: " << e->code();

        if (e->message())
        {
            wcout << L", " << e->message();
        }

        if (e->hint())
        {
            wcout << L", " << e->hint();
        }
    }

    wcout << endl;
}


Last updated on April 8th, 2017 02:55:54 PM