Good day! Please tell me what is the meaning of the design On E: Exception Do? What is E? Do I understand correctly that this construct responds to any exception?
2 answers
E is an object of class Exception. Yes, this construction really reacts to any exception, further processing boils down to determining the type (for example,
E.ClassName
) and the output of the message (for example,
E.Message
), or other action.
All exceptions:
except On E : Exception do ShowMessage('Error: '+E.Message); end;
Optional:
except // Ошибка ввода-вывода On E : EInOutError do ShowMessage('IO error : '+E.Message); // Деление на ноль On E : EDivByZero do ShowMessage('Div by zero error : '+E.Message); // Все остальное: else ShowMessage('Unknown error'); end;
Something like Switch / case + default
|
I will add
if you need an exception of the EOutOfMemory type, then
on E: Exception do // или on E: EOutOfMemory do if E is EOutOfMemory then
and if you need a whole of all derivatives (eg EMyMemoryError = class (EOutOfMemory)), then so:
on E: EOutOfMemory do
- not at all =) - ADR
|