Hi, new member here.
I've never used the exception handling "try except" construction before, but I would like to use it to trap certain numeric errors in some code that I want to write.
This Delphi help page,
http://www.delphibasics.co.uk/RTL.asp?Name=try&ExpandCode3=Yes#Ex3, gives the following example code for trapping divide by zero, but I can't even get this simple example to work. (Tried in both Delphi 7 and in Lazarus with the same results).
In each case it just seems to ignore my error handler and go straight to the default error trap that terminates the program with -
project1 raised the exception class 'External: SIGPFE'BTW, the following is supposed to be a "generic" exception that should match anything. I know that there are more specific exceptions for divide by zero, but at this stage I'm just trying to get the simplest possible example working, and I can proceed from there.
var
number, zero : Integer;
begin
// Try to divide an integer by zero - to raise an exception
Try
zero := 0;
number := 1 div zero;
ShowMessage('number / zero = '+IntToStr(number));
except
On E : Exception do
ShowMessage(E.ClassName+' error raised, with message : '+
E.Message);
end;
end;