Martin schrieb:
When in case of an unexpected error the called procedure throws an
exception? Can this procedure *ever* be "safely invoked", when it may
return to some other place in code (exception handler)?
Yes, why not. IF this is the defined behaviour. Exceptions can be
caught. To safely call such a function one would need to define an
exception handler. But it can be safely called.
This is not what I undstand as "safely called", when such a call
requires protection by a try-except statement. Then the procedure with
that exception handler cannot be "called safely", because the exception
may lead to only *partial* processing of the try-block.
SEH is not intended for *local* protection against exceptions, this is
the task of try-finally. Instead exceptions should be handled in those
places, where it's possible to *repair* the possible inconsistencies,
caused by an error-abort somewhere down in the call chain.
That a function can be safely called does not mean that there is no way
to call it unsafely.
A function expecting a pointer to some specific data, may be able to
check if the pointer is nil, but it can not necessarily check if the
pointer is otherwise valid.
And this is not related to thread-safety at all. The "safe call" means
nothing but *reentrant*.
Hence input range for which the function is defined, is a pointer that
is nil, or pointing to the correct type of data. Within this range of
input the function may be called and will be safe, with other input the
result of calling the function is not defined, hence it is not safe.
Then almost no procedure can be "safe", in detail in OOP with virtual
methods.
DoDi
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus