Solved

How to avoid an error from displaying the little windows error box

Posted on 1998-10-04
11
298 Views
Last Modified: 2010-04-06
Hi, I would like to know how to avoid any error messages from displaying the little windows error box? The error
don't came from my code it came from an external event so
the try/except statement doesn't work.
What I would like is that instead of seeing the windows error box, my own error message appear in the Memo of my application.
Thanks.
0
Comment
Question by:mabell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1341771
You can avoid some of these windows boxes by using win API SetErrorMode.

Does this help?

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1341772
mabell

here is an example of the API SetErrorMode

var
Errormode : Word;

begin
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
//don't forget to set the errormode back to its normal state
fianlly
 SetErrorMode(ErrorMode);

Later
BoRiS
0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1341773
mabell, you can also make your own exception handler and let it determine which messages to show and which to suppress.

An exception handler is a procedure of the form

TExceptionEvent = procedure (Sender: TObject; E: Exception) of object;

You assign it to the Application object's OnException event, and it then gets called every time an exception occurs in stead of the default exception handler. Depending on the type of exception passed in the E parameter you can take different actions, typically displaying or not displaying an error message, stopping or not stopping the program.

Regards,
AndersWP



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Madshi
ID: 1341774
AndersWP,

you wrote "...instead of the default exception handler...". That is true, but the default exception handler is already a Delphi box, isn't it?
So: Writing an own exception handler is nice, but doesn't suppress the windows error boxes mabell is talking of. Or am I wrong?

Regards, Madshi.
0
 
LVL 1

Expert Comment

by:AndersWP
ID: 1341775
You are right Madshi, an exception handler will only catch those error messages that are shown as Delphi error boxes. BTW, which errors are not? I can think of the 'illegal instruction' error; are there others?

Regards,
AndersWP
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1341776
AndersWP,

yes, there are other (quite normal) windows error boxes. Look at SetErrorMode. I don't remember any examples right now, but there are some...

Regards, Madshi.
0
 

Author Comment

by:mabell
ID: 1341777
Thanks all, but can you tell me more info about the SetErrorMode
api like where I put this in my code, what is that value:
SEM_FailCriticalErrors, etc.
You can also give me a web site who give me this type of information.
Thanks.
0
 

Author Comment

by:mabell
ID: 1341778
Thanks all, but can you tell me more info about the SetErrorMode
api like where I put this in my code, what is that value:
SEM_FailCriticalErrors, etc.
You can also give me a web site who give me this type of information.
Thanks.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1341779
I don't have a website. These apis are just described in the win32.help file...
I'm calling "SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX)" in the beginning of each and every of my programs. Perhaps it's not the way Microsoft has it planned - but I just don't want windows error boxes!

Regards, Madshi.

0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1341780
mabell

Here is a snippet I used to check if the disk is in drive A:

function DiskInDrive(Drive: Char): Boolean;
var
  ErrorMode: word;
begin
  { make it upper case }
  if Drive in ['a'..'z'] then Dec(Drive, $20);
  { make sure it's a letter }
  if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Not a valid drive ID');
  { turn off critical errors }
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  try
    { drive 1 = a, 2 = b, 3 = c, etc. }
    if DiskSize(Ord(Drive) - $40) = -1 then
      Result := False
    else
      Result := True;
  finally
    { restore old error mode }
    SetErrorMode(ErrorMode);
  end;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 DiskinDrive(Key);
end;

Here I do the check, hide windows error, display mine etc.

As for the web site I'm not sure windows api stuff is not found that often on the web...

Later
BoRiS
0
 

Accepted Solution

by:
smartass earned 50 total points
ID: 1341781
The answer to your original q is easy (I think if I'm understanding it right?) in the menu tools enviromental options you should simply uncheck the break on exception box and delphi won't break on exceptions (wow that sounds really inteligent but hey it works)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question