2013-11-21 45 views
1

我想確保評估aBlock只會引發SomeCustomError類型的錯誤。有沒有比使用isKindOf更好的方法:?重新排列異常,除非它們屬於某種類型

aBlock 
    on: Core.Error 
    do: [:ex | 
     (ex isKindOf: SomeCustomError) 
     ifTrue: [ex pass] 
     ifFalse: [(SomeCustomError identification: #generalError messageText: ex messageText) raise]] 

回答

1

另一種方法 - 定義方法isMyTerribleException類異常,它應該返回。在您的CustomException類中定義的方法重新定義與返回真正

aBlock 
    on: Core.Error 
    do: [:ex | 
     (ex isMyTerribleException) 
     ifTrue: [ex pass] 
     ifFalse: [(SomeCustomError identification: #generalError messageText: ex  messageText) raise]] 

這將是更好,因爲你可以在引入新的異常類,必須逮住

1

這聽起來很奇怪,我。有兩件事情

1)HOW:

您是從處理程序上下文resignalling。 它真的是你想要的嗎?
或者你想從原始上下文中提出第一個錯誤的位置?

你應該使用類似後者的情況:

ex resignalAs: (SomeCustomError identification: #generalError messageText: ex messageText) 

2)內容:

這不是isKindOf:這困擾我,但整個想法...
捕獲所有類型的錯誤,並由具體的一個取代?
什麼是用例?
誰會抓住特定的一個?
或者特定的人有不同的默認操作?

+0

此代碼在導入器類中使用,我希望導入功能在導入出錯時僅拋出SomeCustomError。但#XMLate:XML.Schema 有時會拋出純粹的錯誤異常。 – Cantillon

相關問題