範例


public class SpecificException extends Exception {

public SpecificException() {
super();
}
}


public class Example {
public void compute(Object subject) throws SpecificException {
if (subject == null){
throw new SpecificException();
}
//...
}

public void declaresException(Object o) throws Exception {
compute(o);
}
}

解決方案
在 throws 子句中宣告所有檢查的異常狀況。


public class SpecificException extends Exception {
public SpecificException() {
super();
}
}

public class Solution {
public void compute(Object subject) throws SpecificException {
if (subject == null) {
throw new SpecificException();
}
//...
}

public void declaresException(Object o) throws SpecificException {
compute(o);
}
}