answersLogoWhite

0


Best Answer

The throw keyword is used to throw an exception that may be generated in a code block. Ex: if (some condition){ throw new CannotProcessFileException("InvalidFile"); } The throws keyword is used in method signatures to signify the fact that, this method would be throwing exceptions of the type specified if the code in the method happens to generate one. Ex: public String getNameFromDB(int id) throws SQLException {

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

The throw keyword is used to throw an exception that may be generated in a code block. Ex: if (some condition){ throw new CannotProcessFileException("InvalidFile"); } The throws keyword is used in method signatures to signify the fact that, this method would be throwing exceptions of the type specified if the code in the method happens to generate one. Ex: public String getNameFromDB(int id) throws SQLException { … }

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Describe how throw and throws clause differ when implementing exception handling in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How does a try statement determine which catch clause should be used to handle an exception?

When an exception is thrown within the body of a try statement, the catch clauses of the try statement are examined in the order in which they appear. The first catch clause that is capable of handling the exception that was thrown, is executed. The remaining catch clauses are ignored


How exception handling differs in C plus plus and Java?

Exception handling is largely the same for both. The only real difference is that C++ has no 'finally' clause which always executes whether an exception occurs or not. Another difference is that Java throws exceptions and errors, but errors cannot be handled since programs cannot handle errors -- such as the JVM out of memory error.


A dependent clause used to describe a verb adjective or adverb?

adverb clause


What is used to explain or describe a noun in a subordinate clause?

A relative pronoun, such as "who," "which," or "that," is commonly used to explain or describe a noun in a subordinate clause. These pronouns connect the subordinate clause to the main clause and provide additional information about the noun.


Which exception is raised by a CASE statement when no match is found and the ELSE clause is omitted from the statement?

case_not_found


What can describe a verb an adjective a phrase or a clause?

Any of an adverb, an adverb phrase or an adverb clause can describe a verb.Adverb: She swam smoothly.Adverb phrase: She swam through the water.Adverb clause: She swam when she saw the turtle.


What is the noun clause in this sentence What took place in the courtroom was hard to describe?

The noun clause is, 'What took place in the courtroom'. The noun clause is acting as the subject of the sentence.


What is the use of a finally clause?

Finally is used in exception blocks:try{...}catch(...){...}finally{...}Finally is used if you need to do something in case if an exception was occurred. And if it cannot be done in the catch block.


What is throw exception in java?

The presence of the keywords "throws exception" on a method signature means that, the method may throw an exception whhich it does not handle. It also means that the method that is calling or invoking it has to handle such exceptions. If the calling method does not handle that exception it would have to in turn use the same "throws exception" clause and throw it to its parent method.


What is an exception to the full faith and credit cause?

An exception to the full faith and credit clause is the public policy exception. This exception allows a state to refuse to recognize a law or judgment from another state if doing so would violate the public policy of the state being asked to enforce the law or judgment.


Is except a conjunction or a preposition?

"Except" can function as a conjunction introducing a clause that excludes something, or as a preposition indicating exclusion or exception.


What part of speech is except for?

The phrase "except for" can be used as a preposition or a conjunction. As a preposition, it introduces a phrase that excludes or does not include something. As a conjunction, it is used to introduce a subordinate clause that expresses an exception or contrast to the main clause.