- Код: Выделить всё
Type
{ BExceptionClass }
BExceptionClass = Class(Exception)
Private
bCode: Integer;
Public
Property Code: Integer Read bCode;
Constructor Build(Const aCode: Integer; Const aMessage: String);
Constructor Build(Const aCode: Integer; Const aMessageMask: String;
Const aParams: Array Of Const);
Destructor Burn;
End;
..
Constructor BExceptionClass.Build(Const aCode: Integer; Const aMessage: String);
Begin
bCode := aCode;
Inherited Message := aMessage;
End;
Constructor BExceptionClass.Build(Const aCode: Integer;
Const aMessageMask: String; Const aParams: Array Of Const);
Begin
bCode := aCode;
Inherited Message := Format(aMessageMask, aParams);
End;
Всё хорошо, но как теперь в одном Try'e обрабатывать 2 типа Exception'a?
- Код: Выделить всё
Begin
Try
Case Random(3) Of
0: StrToInt('blah');
1: Raise BExceptionClass.Build(147, 'Тупо не повезло');
2: WriteLn('Epic win');
Else
Raise BExceptionClass.Build(148, 'WTF?!!!111oneone');
End;
Except On E: BExceptionClass Do
WriteLn(E.Code, ' :: ', E.Message);
End;
Вариант с
- Код: Выделить всё
Except On E: Exception Do
If E Is BExceptionClass Then WriteLn(BExceptionClass(E).Code, ' :: ', E.Message)
Else WriteLn('-1 :: ', E.Message);
представляется несколько громоздким... Вложенный Try - ещё хуже... Нет ли способа адекватней?