Hello,
I see that a common action can be used for all possible exception writing code like this (the code is meaninful just to illustrate the concept)
procedure TForm1.Button2Click(Sender: TObject);
var
a, b, c : double;
begin
try
a:=1;
b:=0;
c:=a/b;
except
MessageDlg('Something went wrong', mtError, [mbOK], 0);
end;
end;
I see that except section allows specialize the answer like this (Still covering all the possible exception thanks to “else”)
procedure TForm1.Button3Click(Sender: TObject);
var
a, b, c : double;
begin
try
a:=1;
b:=0;
c:=a/b;
except
on E:EZeroDivide do
MessageDlg('Division by 0', mtError, [mbOK], 0);
on E:EMathError do
MessageDlg('Computational Error', mtError, [mbOK], 0);
else
MessageDlg('Something unexpected went wrong', mtError, [mbOK], 0);
end;
end;
Now my question: how implement an exception section that do something in ”all the cases” but then lefts the specialized case do the rest of the job? I would like something like
var
a, b, c : double;
begin
try
a:=1;
b:=StrToFloat(Edit1.text);
c:=a/b;
except
//MessageDlg('Something went wrong', mtError, [mbOK], 0); <-- code needed for all exception cases, it does not compile
on E:EZeroDivide do
MessageDlg('Division by 0', mtError, [mbOK], 0);
on E:EMathError do
MessageDlg('Computational Error', mtError, [mbOK], 0);
on E:EConvertError do
MessageDlg('Conversion Error', mtError, [mbOK], 0);
end;
end;
How can I achieve this behaviour ? are there other ways to achieve this ?
Thank you