Search code examples
indyhttp-erroridhttpc++builder-xe7

How to suppress Indy IdHTTP error message box?


I have an IdHTTP component and when I get a HTTP error (for example 404) Indy shows a message box. I want to handle this "silent" and prevent Indy from showing this.

I have not found any parameter to turn this off. Any ideas?


Solution

  • Indy does not display message boxes. It throws exceptions. There are default exception handlers inside the VCL/FMX framework that will display a message box to the user if an exception is not caught in your code. So simply catch the exception in your code, eg:

    try
    {
        IdHTTP1->Get(...);
    }
    catch (const Exception &)
    {
        // do something...
    }
    

    If you need finer control over the exception filtering, all Indy-specific exceptions are derived from EIdException, and there are many descendants (like EIdHTTPProtocolException), eg:

    try
    {
        IdHTTP1->Get(...);
    }
    catch (const EIdHTTPProtocolException &)
    {
        // an HTTP error occured, do something...
        // details about the HTTP error are in the exception object
    }
    catch (const EIdException &)
    {
        // a non-HTTP Indy error occured, do something else...
    }
    catch (const Exception &)
    {
        // some other error occured, do something else...
    }