Wilfried Mestdagh wrote:
> Hello Rob,
>
>
>>However, the name of your TrigerError procedure doesn't seem right.
>>You're not really _triggering_ the error in that procedure. The error
>>has already occured, and you're telling the procedure what the error was.
>
>
> I use TriggerXXX in my objects to Trigger an event. For example:
>
> procedure TSomeObj.TriggerError(E: Exception);
> begin
> if Assigned(FOnError) then
> FOnError(Self, E);
> end;
If you just want to notify an event handler of an error condition
like that, that's really not what exceptions are for, just pass
some kind of error code.
If you expect the Event handler to maybe SOMETIMES raise the
passed in exception (and what happens if there's no event handler
assigned?); I'd say a better approach would be to pass a test
variable to the event handler so the handler can say whether or
not it wants an exception raised, e.g.:
procedure TSomeObj.TriggerError(E: Exception);
var
RaiseException: Boolean;
begin
RaiseException := False; // or True if you want it
// generally to be raised regardless
if Assigned(FOnError) then
FOnError(Self, RaiseException);
if RaiseException then
raise E;
end;
This keeps control of the exception raising in your code rather
than relying on the event handler writer to know what to do with it.
> procedure TSomeObj.Foo;
> begin
> try
> DoSomethingWhereCanBeAnExceptionInIt;
> except
> on E: Exception do
> TriggerError(E);
> end;
> end;
>
> This codes very fast and reliable, also for maintance. Is this not a
> good technique ?
That's perfectly fine, in this context E has already been raised
in order for the "on E" code in the except block to be executed.
You're previous post implied that there you were just creating an
exception instance without a try..except block and there was no
exception actually being raised anywhere.
Stephen Posey
[EMAIL PROTECTED]
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk