java异常处理1

title: 布尔类型或者异常

tags:

当这个方法需要抛出多个异常的,也就是多中可能的时候,那么使用异常
当你只需要知道对或者错,对其他的错误不感兴趣的时候,那么使用布尔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public void (){

validate(some_object_or_condition);

}
private void validate(Object arg) {
// Code that validates the argument and throws an exception if it's invalid
}

public void () throws Exception {

if( !isValid(some_object_or_condition) );

}

private boolean isValid(Object arg) {
// Code that returns a boolean based on whether or not the argument is valid
}