RAD Studio |  |

Defining Your Own VCL Exceptions
See Also
Collapse All

Because VCL exceptions are classes, defining a new kind of exception is as simple as declaring a new class type. Although you can raise any object instance as an exception, the standard VCL exception handlers handle only exceptions that descend from Exception.

New exception classes should be derived from Exception or one of the other standard exceptions. That way, if you raise your new exception in a block of code that isn't protected by an exception handler specific to that exception, one of the standard handlers will handle it instead.

For example, consider the following declaration:

Copy Code

    type
      EMyException = class(Exception);

Copy Code

    class EMyException : public Exception
    {
    };

If you raise EMyException but don't provide a specific handler for it, a handler for Exception (or a default exception handler) will still handle it. Because the standard handling for Exception displays the name of the exception raised, you can see that it is your new exception that is raised.

See Also

VCL Exception Classes

Default Exception Handling in VCL

Silent Exceptions

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!