00 Votes

Delphi: Catching Errors with Try Except is not working

Question by Compi | 2012-09-12 at 19:50

In my Delphi application, I want to capture some possible errors, to save them in a memo so that I can evaluate them afterwards. The users of the program should not get an error message.

On the Internet, I have read that you can do this with Try and Except. A try-except block should prevent an exception error message. However, that does not seem to work for me.

My code for the entire test looks like this:

try
  arr[10]:=0;  // 10 is outside of the array
except
  on E:Exception do memo1.lines.add('Fehler');
end; 

I access an array outside of its rank and trigger an error message with this. The error should be written in the memo, instead I still get the stupid Windows message "Access Violation" displayed. Exactly this is supposed to be prevented? What am I doing wrong?

ReplyPositiveNegative
3Best Answer3 Votes

Do you start your program out of Delphi or do you start the EXE outside the IDE?

I suspect, that you start the EXE from within the IDE, where exceptions are displayed depending on the settings, even if they will be suppressed outside the IDE.

Try to start the EXE outside of Delphi, and test, if it works there.

After in the Delphi IDE, an exception has occurred, you can also continue the program with pressing F9. Then you should also see within the IDE, how is written to the memo.

In the options of Delphi you can also disable the exceptions, which I do not recommend, however, as it is quite helpful to be informed about errors.
2012-09-14 at 23:53

ReplyPositive Negative
Reply

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.