answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2009-04-25 08:23:00

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 {

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

User Avatar
Wiki User
Answered 2009-04-25 08:23:00

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 { … }

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Still Have Questions?

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 unchecked exception?

An exception for which it is not required to provide a local try statement, or to propagate via a throws clause defined in the method header. An exception that is not handled will cause program termination if it is thrown


What best describe a clause?

A clause have a subject and verb in it. A clause can be independent or dependent. A independent clause can stand on it's own while a dependent one can't Hope this helps ^^


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.


Which is an exception to the full faith and credit clause?

cannot enforce the criminal law of another state


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 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.


Describe the Necessary and Proper clause?

expand the power of the goverment


What is the difference between throw and throws in Java?

Throw is used to actually throw the exception, whereas throws is declarative for the method. They are not interchangeable.public void myMethod(int param) throws MyException{if (param {throw new MyException("Too low!);}//Blah, Blah, Blah...} The Throw clause can be used in any part of code where you feel a specific exception needs to be thrown to the calling method.If a method is throwing an exception, it should either be surrounded by a try catch block to catch it or that method should have the throws clause in its signature. Without the throws clause in the signature the Java compiler does not know what to do with the exception. The throws clause tells the compiler that this particular exception would be handled by the calling method.


How would you describe the supremacy clause?

The Supremacy Clause is a clause in Article VI of the U.S. Constitution. It states that federal laws take precedence over state laws.


What is the exception to the regular observance of the Full Faith and Credit Clause?

Enforcement of other states' criminal laws


What will happen if an exception does not have a matching catch clause?

The exception will be passed up the call stack. If there is no handler on the call stack, the program will terminate with an unhandled exception error. This is why your main function must have a catch-all exception handler. If your program could throw, always assume it will throw.


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

A type of pronoun.


What is one exception to the full faith and credit clause?

A major exception is the public policy exception. Federal courts are less likely to force a state to enforce the laws of a second state where that law conflicts with the public policy of the first state.


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 the purpose of the finally clause of a try-catch-finally statement?

The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. It is usually used in places where we are connecting to a database so that, we can close the connection or perform any cleanup even if the query execution in the try block caused an exception


Identify the complete adjective clause in He is the one for whom the message was intended?

The adjective clause is in bold: "He is the one for whom the message was intended.", used to describe the predicate nominative 'one'.


What is checked exception?

A compiler for the Java programming language checks, at compile time, that a program contains handlers for checked exceptions, by analyzing which checked exceptions can result from execution of a method or constructor. For each checked exception which is a possible result, the throws clause for the method or constructor must mention the class of that exception or one of the superclasses of the class of that exception. This compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled.


What do you describe river using relative clause?

The river, which twists and turns through the landscape, rushes toward the sea.


English grammerTge student who helped you has been moved to another areawhat kind of relative clause?

It is cosidered as a defining relative clause, it is to describe the preceding noun( the student), and it is essential to the clear understanding of the noun.


A dependent clause used to describe a noun or a pronoun?

A dependent clause is a part of a sentence that contains a subject and a verb but does not form a complete thought and can't stand on its own. Example of a dependent clause that describes a noun:The blue vase that my mother gave me looks so good filled with daisies.The dependent clause 'that my mother gave me' describes the noun vase.


How can you access the value throw an array?

You cannot throw an array, only exceptions can be thrown. You access the thrown exception by catching it in a catch clause of a try...catch statement.


Still have questions?