Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-10-04
11
Medium Priority
?
320 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 200 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

636 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