what difference between throw and throws in exception
handling.
Answers were Sorted based on User's Feedback
Answer / narayana reddy
throws indicates what type of exception is thrown by
a particular function, where as throw is used to through
user defined exceptions
Is This Answer Correct ? | 14 Yes | 0 No |
Answer / archana
throws is to handle exception by the system itself
whereas throw used by the user to handled the exception
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / sidd
In case of java if any error occur deuring the exicution
time throw is use to throwing that that into our catch block
for handling and in case of throws if any error
will occur throws can handle that error.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / dani
You can declare multiple exception thrown by method in
throws keyword by separating them in common
e.g. throws IOException, ArrayIndexBoundException etc,
while you can only throw one instance of exception using
throw keyword e.g. throw new IOException("not able to open
connection").
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / aravinda reddy
Whenever we want to force an exception then we use throw
keyword,throw keyword can also be used to pass a custom
message to the exception handling module i.e. the message
which we want to be printed. throw we will use at statement
level.
Whereas when we know that a particular exception may be
thrown or to pass a possible exception then we use throws
keyword. Point to note here is that the Java compiler very
well knows about the exceptions thrown by some methods so
it insists us to handle them. Method Level
Is This Answer Correct ? | 0 Yes | 1 No |
What are the Abstract Classes provided by Java?
What is difference between overloading and overriding?
What are the five major types of reference sources?
Is it possible to write static method in abstract class? justyfy your answer?
how to make a un-checked exception as a checked exception one.
Is math class static in java?
what is mena by object block any what is the use of that
Can we call virtual funciton in a constructor ?
Difference between Web-based applications,Client- Server applications and Distributed applications?
What about main thread in java?
What is synchronization and why is it important in java programming?
java is puerly object oriented or not ?