私try-catch
のphpアプリケーションに次のようなブロックがあります:
try {
if ($userForgotToEnterField) {
throw new Exception('You need to fill in your name!');
}
...
doDifferentThingsThatCanThrowExceptions();
...
} catch (ExpectedException $e) {
$template->setError('A database error occured.');
} catch (Exception $e) {
$template->setError($e->getMessage());
}
カスタムエラーテキストを使用して手動でスローした例外のみを出力したいと思い$e->getMessage()
ます。他のコードによってスローされた例外には、機密情報やユーザーに表示されるべきではない非常に技術的な情報が含まれている可能性があるため、出力したくありません。
カスタム例外クラスを使用せずに、手動でスローされた例外と何らかのメソッドによってスローされたランダムな例外を区別することは可能ですか?