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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -