有没有办法从异常处理程序中操纵实例化的类属性? 可以说有一类汽车,上面有名称和价格, 还有一个自定义例外 在驱动程序类中,我实例化该类并尝试创建汽车
String name = "car name";
Double price = 222.00;
try {
Automobile car = new Automobile(name, price) //creates the car object
}catch(CustomException e) {
e.fix()
}
在fix方法中,Custom异常实例化一个有效的car对象。如何从上方将汽车对象设置为从异常生成的汽车对象。条件是自定义异常不能返回任何内容。
You can split declaration and assignement and declare
car
outside of thetry
-block as follows: