java - Throw exception in class declaration -


i trying throw exception in declaration of class. this:

class myclass throws a_dangerous_exception implements something_to_implement {  ...  } 

any suggestions?

you can't that. mean throw exception class' constructor:

class myclass implements something_to_implement {   myclass() throws a_dangerous_exception {} } 

if have multiple constructors, each 1 can have different throws clause if want:

class myclass implements something_to_implement {   myclass() throws a_dangerous_exception {}   myclass(int a) throws a_dangerous_exception, a_not_so_dangerous_exception {} } 

then, whenever instantiate class, have deal exception(s), either catching them or declaring them in throws clause of method instantiate class:

void mymethod() {   try {     new myclass();   } catch (a_dangerous_exception e) {} } 

or

void mymethod() throws a_dangerous_exception {   new myclass(); } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -