Stop Program Popup Errors and exceptions

Hi all,

I'm writing a program that does everything on timer basis.
And the program will be sitting on the windows tray, unattended.
When there is an error, i get a popup message, instead i want it to write the error on a memo.
I've tried:

Try...

execpt... etc...

and also the windows critical error stopping function, but i still get a popup.

How can i stop this?  And i mean with any exception or error?

Thanks

SFern.
sfernAsked:
Who is Participating?
 
shaneholmesConnect With a Mentor Commented:
Your blank app should look like this

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure DisplayExceptions(Sender: TObject; E: Exception);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DisplayExceptions(Sender: TObject; E: Exception);
begin
 Memo1.Lines.Add(E.Message)
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnException:= DisplayExceptions;
end;

end.
0
 
shaneholmesCommented:
override the Applications.OnExeception and

Write it out to your memo

protected
 procedure DisplayExceptions(Sender: TObject; E: Exception);


 procedure TForm1.DisplayExceptions(Sender: TObject; E: Exception);
 begin
 Memo1.Lines.Add(E.Message);
 end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnExeception:= DisplayExceptions;
end;
0
 
shaneholmesCommented:


or get madExcept at www.madshi.net

Shane
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
esoftbgCommented:
try
// ..........
except
  on e : exception do
    Memo1.Add(e.Message);
end;

You will get a popup only when run your application under Delphi IDE. When you run it by the .exe file, you will don't get a popup exception....
0
 
shaneholmesCommented:
i didn't mean to say - "override" the Applications.OnExeception, i meant to say

Assign your own  method to the Applications.OnException


This works great,, cause it prevents you from having to place try ... except blocks everywhere in you program,

its global and will catch them all....

Shane
0
 
sfernAuthor Commented:
If trying the first example but i get:

Undeclared identifier OnExeception :(

What i'm i doing wrong, i'm i putting the Protected in the wrong place?

Thanks
0
 
shaneholmesCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
   procedure DisplayExceptions(Sender: TObject; E: Exception);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DisplayExceptions(Sender: TObject; E: Exception);
begin
 Memo1.Lines.Add(E.Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnException:= DisplayExceptions;
end;

end.
0
 
sfernAuthor Commented:
I'm getting the same error, does it require an addition in the uses section?

this is how it looks:
.....

 private
    { Private declarations }
    procedure AddToListView(Value, From: string);
    procedure ToggleStatus(const Status: Boolean);

  public
    { Public declarations }

  protected
  procedure DisplayExceptions(Sender: TObject; E: Exception);
......

implementation

{$R *.dfm}

procedure TOBJ_MainForm.DisplayExceptions(Sender: TObject; E: Exception);
 begin
 Memo1.Lines.Add(E.Message);
 end;

.......


procedure TOBJ_MainForm.FormCreate(Sender: TObject);
begin
Application.OnExeception:= DisplayExceptions;

SendingMail:=False; //Set SendingMail to False
Statusbar1.Panels[1].text := ('Disconnected');

If POP.Connected then
POP.Disconnect;


if Win32Platform = VER_PLATFORM_WIN32_NT then
    Font.Name := 'MS Shell Dlg 2'
  else
    Font.Name := 'MS Shell Dlg';
end;

.....


I'm getting 2 errors:

Undeclared identifier OnExeception

and

Not enough actual parameters.

What i'm i doing wrong?

Thanks




0
 
shaneholmesCommented:
hmmm, what version of delphi are you using....

SHane

0
 
shaneholmesCommented:
Try creating a blank application and try pluggin in my code and see what you get

SHane
0
 
sfernAuthor Commented:
OK, thanks, i have to try it a bit later though, from home.

I'll let you know later..thanks :)

0
 
sfernAuthor Commented:
Cannot get it to work, same errors :(

Any ideas?

Thanks
0
 
shaneholmesCommented:
Again, what version of delphi????

Shane
0
 
shaneholmesCommented:
and did you create a blank application?

Shane
0
 
sfernAuthor Commented:
yes :(

I'm using delphi 6 Ent
0
 
shaneholmesCommented:
k, open up help, search for TApplication, and look at its events

You should see OnException

Shane
0
 
shaneholmesCommented:
Let me know if you find it?

Shane
0
 
sfernAuthor Commented:
Ok, i tried again and managed to make it work on a new application but for some reason the

formcreate section gives me those errors

Very strange :(
0
 
shaneholmesCommented:
hmmm - in your application , or in the new blank application.

Cause i dont get any errors in my Form Create

Shane
0
 
shaneholmesCommented:
you can actually place it anywhere you like - but the higher up the ladder, the more likely you are to miss exceptions  - thats why i suggest in the form create. You could also assign it in the form's onActivate

or .... in the project source, but since you will be writing your exceptions to a tmemo, you will want it in the main form.

Shane


0
 
sfernAuthor Commented:
This part gives me the errors, the rest are accepted.

procedure TOBJ_MainForm.FormCreate(Sender: TObject);
begin
Application.OnExeception:= DisplayExceptions;  // <---This line !!!

SendingMail:=False; //Set SendingMail to False
Statusbar1.Panels[1].text := ('Disconnected');

If POP.Connected then
POP.Disconnect;


if Win32Platform = VER_PLATFORM_WIN32_NT then
    Font.Name := 'MS Shell Dlg 2'
  else
    Font.Name := 'MS Shell Dlg';
end;
0
 
shaneholmesCommented:
Did you try doing it in a blank project?

Shane
0
 
shaneholmesCommented:
Never mind, i think i know why

add that line to the form's onActivate event

Shane
0
 
shaneholmesCommented:
Not that i think of it, the window handle to Memo is not created yet, therefor you will get a error message, so therefore the lowerst level for you would be form's onactivate event - place it there

Shane
0
 
sfernAuthor Commented:
Same error :(

This is REALLY STRANGE
0
 
sfernAuthor Commented:
Undeclared Identifier??????????

It's declared :(

0
 
shaneholmesCommented:
OK, paste me here the whole unit from the blank project you created with just the memo on it

Shane
0
 
sfernAuthor Commented:
It does'nt know Onexception :(


Strange !!!
0
 
shaneholmesCommented:
If it does and your still getting errors, then you definetly have a faulty install of delphi - is all i can say

double check your uses clause as well, make sure everything matches up

Shane
0
 
sfernAuthor Commented:
Got it !!!

Spelling mistake, it's now compiling!!!

but i still get a popup message on this line:

if (ChilkatMailMan1.SendEmail(email) = 0) then //on mail error
         begin

      Memo1.Lines.Add('Error found');

should i take it off?

0
 
shaneholmesCommented:
when you compile and run it outside of delphi ide do you get it as well

Shane
0
 
sfernAuthor Commented:
I'll check
0
 
sfernAuthor Commented:
GREAT!!!! It's now working...wow...application completed :)

I'm giving you the rest of my points that i have left.

Thanks for all your great help :)

0
 
sfernAuthor Commented:
Did you get your points?
0
 
shaneholmesCommented:
yes, thanks!

Shane
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.