Reputation: 2060
Everytime I use a raise Exception.create('...');
, it shows, differently from Delphi, the following box:
[my message]
Press OK to ignore and risk data corruption.
Press Cancel to kill the program.
I just want to change this default message and keep only my part.
Does someone know how can I do it?
Upvotes: 3
Views: 2129
Reputation: 2060
To configure my own exception message, I did the following:
In the private declarations of application's main form:
procedure onExcept(sender: TObject; e: Exception);
In the OnCreate event of the main form:
procedure TfrmMain.formCreate(sender: TObject);
begin
application.onException := @onExcept;
end;
procedure TfrmMain.onExcept(sender: TObject; e: Exception);
begin
//...
end;
It's important to note that the @ operator is required if you're using Lazarus. If I didn't put it, the compiler would consider onExcept
as a function call. Delphi adds it internally, so you don't have to worry about it.
If you want to change this behavior, use {$mode Delphi}
instead of {$mode ObjFPC}
directive.
Upvotes: 2