[Lazarus] Exception dialog

Michael Van Canneyt michael at freepascal.org
Tue Mar 17 13:34:57 CET 2009



On Tue, 17 Mar 2009, Martin Friebe wrote:

> Luca Olivetti wrote:
> > En/na Hans-Peter Diettrich ha escrit:
> >
> >   
> >> Insert your exception handler in an more appropriate place, depending on 
> >> the concrete application. The user can expect a diagnosis of what went 
> >> wrong, and a chance for correcting his preceding input.
> >>     
> >
> > For data aware components (and probably for others too), 
> > Application.OnException is the only place, otherwise you cannot trap 
> > exception that are no caused by your program flow but by intrinsic 
> > processing by the component (e.g. during post the database could reject 
> > the data due to failed constraints, you could trap BeforePost or 
> > AfterPost but not DuringPost).
> >   
> If a component throws an exception outside any call  from your code 
> (which you can place in a "try except end"), a place like OnDataReceived 
> which is triggered automatically, then this component has a bug (IMHO).
> The component *should* have something like an OnError event on which it 
> can call your code. Or it should have a flag/state, on which it said 
> that an error occurred.
> An Exception may be, if an OnError event is provided, but not assigned.

Why ? 

In the OnValidate event of a TField, you are supposed to throw an exception 
to stop the user from entering wrong data in the field. This exception can 
only be caught by the program event loop. This is so by design, and the
recommended way by Borland.

Michael.



More information about the Lazarus mailing list