Answer the question
In order to leave comments, you need to log in
Why is there no exception handling?
The simplest code. The message - An exception has occurred does not appear. Any code in the except section is not executed.
If you take out the code c:=a div b; outside of the try-except, the program will report Division by zero.
Why is there no exception handling?
procedure TForm1.Button2Click(Sender: TObject);
var
a,b,c:integer;
begin
a:=1;
b:=0;
try
c:=a div b;
except
ShowMessage('Возникло исключение.'); //Это сообщение не появляется
end;
end;
Answer the question
In order to leave comments, you need to log in
For me (Delphi 7), your code is apparently destroyed by the optimizer, because it does not use the value of the variable c, it’s too lazy to disassemble, but it looks like this, because if you make it used, it works:
procedure TForm1.Button1Click(Sender: TObject);
var
a, b, c: integer;
begin
a := 5;
b := 0;
try
c := a div b;
ShowMessage(FloatToStr(c)); // --
except
ShowMessage('test');
end;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question