← Back to context

Comment by ameliaquining

5 hours ago

How do native exceptions work in Delphi?

Very similar to Windows Structured Exception Handling, which the Win32 implementation used, and also looks similar to Java, but without checked exceptions. try/except/end and try/finally/end blocks.

The major differences with C++:

    * objects are references not values, cutting out all the copy constructor,
      assignment operator, destruction on out of scope etc.
    * objects are zero-initialized after allocation and before constructors run
    * constructors are run from most derived to least derived
    * calling Free method checks if Self is nil
    * this + zero init means that you can call '.Free' on all the objects you 
      reference in the destructor without checking if they're nil first, 
      handling partial construction

It's not a memory safe language, but it does give you a bunch of idioms that, if you stick to them, you don't feel nearly as much pain as C++.