We help IT Professionals succeed at work.

Error handler! HELP

SULTAN
SULTAN asked
on
hi

How do I trap the anoying error MSGs that some times pop upp in my App??? Maybe just nott display them or just logg them to a TMemo?

Like a OnError  event

Any ideas
Comment
Watch Question

Commented:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    procedure OnException(Sender: TObject; E: Exception);

    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.OnException(Sender: TObject; E: Exception);
begin
  caption:=e.Message; //Message text
end;


procedure TForm1.Button1Click(Sender: TObject);
var x: real;
begin
  x:=0;
  caption:=Floattostr(1/x);
end;

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

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.OnException:=nil;
end;

end.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.