このコンテキストでは、raise操作は効果がなく、例外ブロックがキャッチしたばかりの例外を単に再発生させるため、削除する必要があります。通常、raiseは、適切なエラー処理が利用できない場合に、ブロックの最後に制御を移すために使用されます。以下では、カスタム例外を処理しますが、その他の例外は他の場所で処理する必要があります。
try
someOperation;
except
on e: ECustomException do
SomeCustomHandelr;
else
begin
// the raise is only useful to rethrow the exception to an encompasing
// handler. In this case after I have called my logger code. as Rob
// mentioned this can be omitted if you arent handling anything because
// the compiler will simply jump you to the next block if there is no
// else.
LogUnexpectedException('some operation failed',e);
raise;
end;
end;
「レイズ」のない似たような形があり、例外を食べたり隠したりするという副作用があることに注意してください。うまくいけば競争のポジションに移動した非常に悪意のある開発者による練習。
with ADOQuery1 do begin
// .. fill out sql.text, etc
try
execSQL;
except
// no handler so this just eats any "errors"
end;