Exceptions In Java

1381 ワード

Javaの例外には、checked Exceptionとunchecked Exceptionの2種類があります.
 Why did the designers decide to force a method to specify all uncaught checked exceptions that can be thrown within its scope? Any Exception that can be thrown by a method is part of the method's public programming interface. Those who call a method must know about the exceptions that a method can throw so that they can decide what to do about them. These exceptions are as much a part of that method's programming interface as its parameters and return value.
1つの方法が所望の値を返さなかった理由は2つあります.1つはcontingency(歪み)、1つはfault(障害)です.
1つのcontingencyはプログラム設計者に考慮され、それをプログラムの正常な行為の一つとしなければならない.それはchecked exceptionに影を落とす方法にとって、contingencyの状況をchecked exceptionに大きく包むべきである.ライブラリクラスのメソッドであれば、メソッドは常に頻繁に発生しないが、返される可能性があるため、checked exceptionで表現され、アプリケーションがメソッドを呼び出すと、状況に応じて個別に処理され、エンドユーザーに正しい値が返されます.このような異常を投げ出しても,プログラムの正常な動作にはまったく影響しないはずだ.
1つのfaultは、unchecked exceptionに対応する設計者が発生しないと考えています.
ひずみと故障の対比
条件
ひずみ
障害
と思われる
デザインの一部
ひどい事故だ
発生が予想される
しばしば起こる
発生しない
注目者
上流呼び出し
問題を探している人を直す必要がある.
価値
もう一つの戻り方
プログラムバグ、ハードウェアシステム障害、構成エラー、失われたファイル、サーバが実行されていません
例外と一致
checked
unchecked
 
参考資料:
Effective Java Exceptions
http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html