picture

Exception Handling in Delphi

Exceptions are a vital language structure of any modern programming language. This posting shows the usage of Delphi’s exceptions.

To raise an exception:


raise Exception.Create('Your exception message');

Excepion is general exception class. Of course you can define your own Exception classes.

To catch exceptions you have several options:


try
  // your code
except
  // exception handling
end;


try
  // your code
except on e:Exception do
  // exception handling, for example :
  showmessage(E.Message);
end;

The combination of except and finally sections looks like this:


try
    try
       // your code
    except on e:exception do begin
       // exception handling
    end;
finally
    // finally section
end;


Comments to the Post

Leave a Reply

For spam detection purposes, please copy the number 6439 to the field below: