Defining Your Own VCL Exceptions

From RAD Studio
Jump to: navigation, search

Go Up to Handling Exceptions in VCL Applications

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:

   EMyException = class(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