我正在重寫第三方庫類提供的方法,并嘗試記錄發生的異常:@OverridesomeJavaMethod(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原則來處理此問題?(另外,建議我查看訪問者和非循環訪問者的設計模式,但是我不確定它們是否可以應用于無法修改的類)
添加回答
舉報
0/150
提交
取消