Domanda

In our application we have created several Exceptions classes for all our needs. But now the problem is, that the raised Exception Dialog always is MessageType mtError and of course shows the mtError-Icon.
For a few of our Exceptions i would prefer a less agressive Icon/MessageType, for example MessageType mtInformation.

Is there any way to change the Icon directly in the Exceptionclass without raising and catching it again with try...except on each occurence?

È stato utile?

Soluzione

You will need to customise the top level exception handler.

Write an event handler and attach it to Application.OnException. You can then handle particular exceptions any way you like.

The event handler will look like this:

procedure TMainForm.ApplicationException(Sender: TObject; E: Exception); 
begin   
  if E is EMyException then
    ShowExpectedMessageBox(E)
  else
    Application.ShowException(E);
end;

Obviously you have to write the code for ShowExpectedMessageBox. This can show a message box using whatever icon you prefer.

The OnException event is called when an unhandled exception reaches the message loop. If you don't have an event handler, the framework calls Application.ShowException. Which is what you should do for those exceptions that do not get your special treatment.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top