2009-06-25
■RE:ある程度の冗長さはコンパイラがまとめてくれる(javac)(というのは早合点)
http://d.hatena.ne.jp/takayukis/20090620/1245470183
http://d.hatena.ne.jp/shin/20090624/p3
横からすみません。ソース見ていたら、うずうずしてきたので。
String msg = null;
try {
pref.save();
} catch (FileNotFoundException e) {
msg = "アプリケーション設定ファイルを作成できません。";
logger.error(msg, e);
} catch (IOException e) {
msg = "アプリケーション設定ファイルを保存できません。";
logger.error(msg, e);
}
if (msg != null) {
MessageBox msgBox = new MessageBox(shell, SWT.OK
| SWT.ICON_ERROR);
msgBox.setText("エラー");
msgBox.setMessage(msg);
msgBox.open();
}
shell.close();
↑のソースならば、メッセージボックス関連をfinallyにまとめるっているのはどうでしょ。
msgがエラーフラグになっているわけですね。って、言いながら、あまり変わらなかったです。
String msg = null;
try {
pref.save();
} catch (FileNotFoundException e) {
msg = "アプリケーション設定ファイルを作成できません。";
logger.error(msg, e);
} catch (IOException e) {
msg = "アプリケーション設定ファイルを保存できません。";
logger.error(msg, e);
} finally {
if (msg != null) {
MessageBox msgBox = new MessageBox(shell, SWT.OK
| SWT.ICON_ERROR);
msgBox.setText("エラー");
msgBox.setMessage(msg);
msgBox.open();
}
}
shell.close();
