# [issue] Java class 需設定拋出 Exception 但又被說不相容的死迴圈 碰過一種情形是維護舊有 class 的 method,當撰寫到 IDE 警告需設定 Exception 時,直覺會遵照介面指示產生拋出(或 try catch ),而這是又出現 XXX Exception is not compatible with throws clause in OOO.***(),看起來好像是不相干的 class,而讓人一時疑惑 這時記得檢查目前所在的 class 是否 implement 那個 OOO class,或正在 override OOO class 中的 ***()!在自行開發時很容易注意到,但在維護舊有 code 時,未必會注意到有這層對應關係 這通常發生在父層設定不拋出 Exception 且沒有對應錯誤處理,所以你在寫的子層如果拋出 Exception 會因沒人接手而導致不相容 當我們在父層設定不拋出 Exception 時,就代表一種保證,保證不會產生此種 Exception,然而在子層我們新撰寫的部分會拋出,這就是一種觸犯禁則的行為,所以會被 block [What are reasons for Exceptions not to be compatible with throws clauses? ](https://stackoverflow.com/questions/10513374/what-are-reasons-for-exceptions-not-to-be-compatible-with-throws-clauses) ###### tags: `Java`