FBX SDK Programmer's Guide > FBX SDK Object Model >

# Error Handling

## Errors

Many member functions of FBX classes may trigger an error. In such a case:

- The function returns false.
- objectname->GetLastErrorString() returns a string with an error message.
- objectname->GetLastErrorID() returns an integer value. You can use FBX enumerated values or defined values to handle the error appropriately.

## Error Handling Sample

The following code appears in Common/Common.cxx. It illustrates the error-handling procedure for a file import operation, including password protection. Some code has been replaced by "// ..." to emphasize the error-handling functionality.

    bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename)
    {
        // ...

        bool lStatus;
        char lPassword[1024];

        // ...

        // Create an importer.
        FbxImporter* lImporter = FbxImporter::Create(pSdkManager,"");

        // Initialize the importer by providing a filename.
        const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings());

        // ...

        if(!lImportStatus)
        {
            printf("Call to FbxImporter::Initialize() failed.\n");
            printf("Error returned: %s\n\n", lImporter->GetLastErrorString());

            if (lImporter->GetLastErrorID() == FbxIO::eFILE_VERSION_NOT_SUPPORTED_YET ||
                lImporter->GetLastErrorID() == FbxIO::eFILE_VERSION_NOT_SUPPORTED_ANYMORE)
            {
                // ... Print an error message ...
            }

            return false;
        }

        // ...

        // Import the scene.
        lStatus = lImporter->Import(pScene);

        if(lStatus == false && lImporter->GetLastErrorID() == FbxIO::ePASSWORD_ERROR)
        {
            printf("Please enter password: ");

            lPassword[0] = '\0';

            scanf("%s", lPassword);
            FbxString lString(lPassword);

            (*(pSdkManager->GetIOSettings())).SetStringProp(IMP_FBX_PASSWORD,      lString);
            (*(pSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true);

            lStatus = lImporter->Import(pScene);

            if(lStatus == false && lImporter->GetLastErrorID() == FbxIO::ePASSWORD_ERROR)
            {
                printf("\nPassword is wrong, import aborted.\n");
            }
        }

        // Destroy the importer.
        lImporter->Destroy();

        return lStatus;
    }