title: 布尔类型或者异常 tags: 当这个方法需要抛出多个异常的,也就是多中可能的时候,那么使用异常当你只需要知道对或者错,对其他的错误不感兴趣的时候,那么使用布尔 123456789101112131415161718 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} 赞微海报分享
近期评论