Next: 1.6 JDK1.4でのThrowableクラス
Up: 1 制御文
Previous: 1.4 例外処理
例外をスローするthrow文は,
throw expression;
という具合になる.
例外をスローするメソッドには,throws節を宣言する必要がある.
メソッドは,メソッド名と両カッコの間の引数のパラメタをシグニチャ
(signature)というが,例外をスローする場合には,シグニチャの後に
throws節を付ける.複数の例外をスローする可能性がある場合には,
それらを列挙する.
public void replaceValue(String anme,
Object newValue)
throws NoSuchAttributeException {
Attr attr = find(name); // attrを探す.
if (attr == null) // 見つからない場合
throw new NoSuchAttributeException(name);
attr.setValue(newValue);
}
generated through LaTeX2HTML. M.Inaba 平成18年5月7日