Dream Lane
Dream Lane

Reputation: 1312

How can I throw an exception for the whole class instead of doing it method by method

I'm writing a program in Java, and nearly every method in one of my classes is written like:

public void doStuff() throws AWTException{}

Is there a way for me to get rid of the extra step of typing throws AWTException for each method, and somehow do it for the entire class?

Upvotes: 22

Views: 14543

Answers (3)

Aditya
Aditya

Reputation: 29

You can by throw exception at constructor level. You can see how FileInputStream force us to throw IO exception while creating object of it.

Upvotes: 1

Ravi Parmar
Ravi Parmar

Reputation: 1452

if you throw exception with class level then how you identify that on which type of exception is thrown by method... or on which method it throw exception.

so it is not allow in java...and also its not a good coding with java

Upvotes: 3

Asaph
Asaph

Reputation: 162801

Sorry, No. There is no way to do this in Java.

Upvotes: 28

Related Questions