java - Should I declare an unchecked exception? -
i've got method invokes method this:
public void m1() { m2(10); } public void m2(int v) { if(v < 10) throw new myexception(); } public class myexception extends runtimeexception{ }
now, i'd notify clients going use m1()
might throw myexception
. ok if declare this:
public void m1() throws myexception{ m2(10); }
i'm not sure used use throws
declaration checked exceptions. common unchecked ones?
you can - , it'll show in javadoc, believe. won't force callers handle exception, you're still relying on users (developers calling code) diligent enough check documentation. if that's sufficient you, go - otherwise, change myexception
checked exception.
as whether it's common declare unchecked exceptions might thrown - i've seen enough not particularly surprising, it's not widely-used practice.
Comments
Post a Comment