最終的には、
if (badThingsHappen) {
log the issue
throw exception with description
}
ここでの明らかな冗長性は、多くの場合、例外の説明とログに記録されるメッセージが(多くの場合)同じであるということです。
これは不必要に冗長に見えます
if (badThingsHappen) {
logger.error("oh no! not again!");
throw new AppException("oh no! not again!");
}
一時的な文字列の宣言は間違っていると感じます
if (badThingsHappen) {
String m = "oh no! not again!";
logger.error(m);
throw new AppException(m);
}
Exceptionのコンストラクターにロギングを処理させても大丈夫ですか?より良い(よりクリーンな)方法はありますか?