Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2026.1

# Handling errors

To encapsulate error handling in a maintainable way, subclass `ClientUser` at least once for every command you want to run and handle errors in the `HandleError()` method of the derived class.

To best handle the formatting of error text, parse the error text, looking for substrings of anticipated errors, and display the rest. For example:

    void P4CmdFstat::HandleError(Error *e)
    {
        StrBuf  m;
        e->Fmt( &m );
        if ( strstr( m.Text(), "file(s) not in client view." ) )
            e->Clear();
        else if ( strstr( m.Text(), "no such file(s)" ) )
            e->Clear();
        else if ( strstr( m.Text(), "access denied" ) )
            e->Clear();
        else
            this->e = *e;
    }

## Connection errors

If any error occurs when attempting to connect with the P4 Server, the `ClientApi::Init()` method returns an error code in its `Error` parameter.

## Server errors

The `ClientApi::Final()` method returns any I/O errors that occurred during `ClientApi::Run()` in its `Error` parameter. `ClientApi::Final()` returns a non-zero value if any I/O errors occurred or if `ClientUser::OutputError()` was called (reporting server errors) during the command run.

To report errors generated by the server during an operation, your application can call the `ClientUser::HandleError()` method. The default implementation of `HandleError()` is to format the error message and call `ClientUser::OutputError()`, which, by default, writes the message to standard output. `HandleError()` has access to the raw `Error` object, which can be examined with the methods defined in `error.h`. Prior to release 99.1, P4 Server invoked `OutputError()` directly with formatted error text.

## Find errorIds

You can find errorIds by running commands on the command line with the `-e` global option. This option displays more detailed information about each error or info message received, including the formatting strings, unique error codes, and severity values that are available to API users.

For more information on global options, see the P4 CLI Reference.

Your search for returned results