Java Style: Properly handling exceptions

后端 未结 5 1478
孤独总比滥情好
孤独总比滥情好 2020-12-13 08:09

I keep getting stuck conceptually on deciding an Exception-handling structure for my project.

Suppose you have, as an example:

public abstract class          


        
5条回答
  •  别那么骄傲
    2020-12-13 08:25

    Throw the IOException wrapped in an exception type that is appropriate to the "Data" class. The fact is that the read method wont always be able to provide the data, and it should probably indicate why. The wrapping exception may extend RuntimeException and therefore not need to be declared (although it should be appropriately documented).

提交回复
热议问题