如果某个“validate”方法返回false,有没有办法捕获异常?
我正在验证给对象的某些值,并且我想抛出异常并打印出错误消息(但继续程序)当valdation(通过构造函数调用)失败时,将不会创建对象 .
if (!validate()) throw new Exception();
1 回答