我正在重写第三方库类提供的方法,并尝试记录发生的异常:
@Override
someJavaMethod(arg1, arg2, Exception ex){
//Declare some variables with default values
if (ex instanceof SpecificException1)
//Set values for the variables
else if (ex instanceof SpecificException2)
//Set some other values for the variables
else
//Do nothing
}
这里的问题是,SpecificException1和SpecificException2都是第三方的异常,我无法修改它们。
我了解使用instanceof并不是解决此问题的好方法。我应该使用哪种设计模式/ OO原则来处理此问题?
(另外,建议我查看访问者和非循环访问者的设计模式,但是我不确定它们是否可以应用于无法修改的类)
波斯汪
慕神8447489
相关分类