4

Is there a way to disable all the dialog boxes when an exception or error occurs(like access violations, indy socket errors, timeouts etc.)? They are thrown sometimes in my program, but these errors aren't fatal in any way and can be ignored, just the dialog boxes are disturbing. I use Delphi 7.

7
  • 3
    You can catch all exceptions, but that is completely wrong and writing such code is a complete lack of professionalism. Access violation is always something wrong and should be handled.
    – LukLed
    Commented Jun 13, 2012 at 18:10
  • 10
    Doesn't it occur to you that you might be better off fixing the bugs in your program? The suggestion that access violations can just be ignored is utterly bizarre. Your program has bugs and the appropriate action is to fix them. Commented Jun 13, 2012 at 18:40
  • You're right about access violations, maybe it was something else(I don't remember, this one occurs very rarely). I know it has many bugs, it's something like 0.1 pre-alpha version of a bot doing some crowdsourcing-like repetitive tasks, many bugs but it's already doing its job. I just wanted temporary solution to run it more flawlessly before I optimize all the things. Anyway thank you for answers. Commented Jun 13, 2012 at 20:48
  • @user1262737 please take into account everything written above and bellow(both comments and answers), otherwise your application will continue to grow in complexity and at some point it's cheaper to rewrite than to continue with it.
    – user497849
    Commented Jun 13, 2012 at 21:16
  • 1
    Just to back up all the others - fix the bugs! It is the only way to progress. Make good use of the exceptions - my current embedded job has no exception handling and it is very painful to locate critical errors. Commented Jun 14, 2012 at 0:55

4 Answers 4

7

If you just don't wont to show the exception window then go to:

Tools/Options/Debugger Options/Language Exceptions and disable CheckBox Notify on language exceptions. That is walid for Delphi 2010.

(I don't remember if it is the same CheckBox in Delphi 7).

EDIT: In some cases the exceptions are unavoidable, specially when we are working with unknown files from internet. So, I believe that your exceptions are handled properly under Indy, just switch-off Notify on language exceptions

1
  • 4
    In Delphi 7, it is similar Tools --> Debugger Options --> Language Exceptions --> untick 'Stop on Delphi Exceptions'
    – Hendra
    Commented Jun 14, 2012 at 5:08
5

You can customize Application.OnException event. But IMVHO...

  • Application.OnException suits best to log exceptions which you forgot to handle.
  • Application.OnException should be used to catch exceptions only when you desperately need performance (in this case you should anticipate broken execution paths).

And:

  • Access violations are fatal errors - you have to trace and get rid of all AV's.
  • You can't hide exception dialogs just by Application.OnException override - you should use try finally/except in right way.
6
  • "You can't just sweep exceptions under the rug like that - you should use try finally/except in right way." Well, the right way is not to use try/except..... Commented Jun 13, 2012 at 19:02
  • 3
    @DavidHeffernan try/except is completely valid, if you used it right way. Eg. not for sweeping under the rug with all covering try..except end;, but doing the actual handling of different exceptions.
    – Harriv
    Commented Jun 13, 2012 at 19:19
  • 1
    @DavidHeffernan: You mean try {...} except {handling any possible exception} end or is there something wrong with try {} except on E: ESpecificException do {handle specific exception only} end I don't know about?
    – g2mk
    Commented Jun 13, 2012 at 19:22
  • Why do you want to handle exceptions? Let it float up to the top level exception handler and deal with it there. There are sometimes exceptions to that rule of thumb, but that's the starting point. Commented Jun 13, 2012 at 19:24
  • 1
    @DavidHeffeman - try/except is a valid programming tool imho, like all other statements. I use it to determine which data sets are valid in a certain computation. If a computation comes up in the except the data set is invalid. if not, the data set is valid. This is a good way to go thru a large number of data sets and marking the correct ones.
    – Arnold
    Commented Jun 14, 2012 at 16:27
2

Bypass the Application.OnException event. However I would NOT recommend hiding every exception, IMHO that is poor design.

0

@ GJ - Delphi 2007 has that check box. But again as was mentioned above, access violation ain't the kind of exceptions that one should ignore.

Not the answer you're looking for? Browse other questions tagged or ask your own question.