Without a full code sample, I can only guess: you are overriding/implementing a method in a subclass, but the exception specification of the subclass method is not compatible with (i.e. not a subset of) that of the superclass/interface method?
This can happen if the base method is declared to throw no exceptions at all, or e.g. java.io.IOException
(which is a subclass of java.lang.Exception
your method is trying to throw here). Clients of the base class/interface expect its instances to adhere to the contract declared by the base method, so throwing Exception
from an implementation of that method would break the contract (and LSP).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…