answersLogoWhite

0

throws exception is a common signature pattern for methods. It is used to signify the fact that the code inside the method may throw exceptions of the types mentioned in the method signature. The calling method must have code to handle the exception effectively.

Ex:

public String getName() throws SQLException {

.....

}

This method's code can throw an SQLEXception and the calling method must have the code to handle this exception

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

What keyword are used in java for exception handling?

The important keywords used in Java with respect to Exception Handling are: a. Throw - The "throw" keyword is used to throw exceptions from inside a method b. Throws - The "throws" keyword is used to signify the fact that the code contents within the current method may be throwing an exception and the calling method must handle them appropriately


What is the difference between throw and throws in net?

"throw" is the keyword to raise an exception. "throws" is a Java keyword that indicates a specific method can potentially raise a named exception. There is no analog in VB.Net or C#. Perhaps there is a "throws" keyword in J#?


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 does the warning Illegal Argument Exception mean in Java language?

The warning Illegal Argument Exception in Java means that one has attempted to pass a wrong type of argument for a function. For example, we have a function that calculates a sum of two numbers and feed it a text string, which results in Illegal Argument Exception.


What is the use of throw statement?

throws keyword/statement is basically used to handle exception in java. throws keyword is used to handle "unchecked exceptions". Example: public void enterdata()throws IOException { BufferedReader inp=new BufferedReader(new InputStreamReader(System.in)); int i=Integer.parseInt(inp.readLine()); } Now after the enterdata function we have used throws keyword because the"readLine" method throws an unchecked exception ie., IOException during user input which cannot be handled by try catch block.


Why should throw keyword is used in java?

Use it when you are implementing something that says it throws a certain exception when a certain condition is met.


How an exception subclass is created in java explain?

We can create a exception sub class by extending Exception class available in java


Does throws throws only unchecked exception?

You can throw any type of exception you want, including an unchecked exception.


Why use throw in java in compare try-catch?

we use throws in our program so that we dont need to write try & catch block & to avoid the exception


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.


What is the purpose of NoMatchException handling method in java?

java exception


Which exception is thrown by the add method of Collection interface in java?

exception


What is the use of throws in java?

The throw keyword in java causes a declared exception to be thrown. For example, if you want to mark an error in a method that add two numbers if any of then is negative you can write something like this:public int addMethod( int a, int b ){if ( a < 0 b < 0 ){throw new ArithmeticException("negative addition");}return a + b;}The previous code cause a ArithmeticException if some try to add negative numbers.


What is difference between exception handling in C and Java?

Easy: there is no exception-handling in C.


Should a method be capable of throwing more than one kind of exception in Java?

It depends actually... It is not a must. If you have method in which there are chances of two different types of exceptions being created, then your method should have a throws clause that can throw both types of exceptions. If you feel your code wouldn't throw any exception then you need not have a throws declaration in your method at all....


When should we use exception handling in java?

Exception handling should be used in Java in all cases where you as a programmer suspect that your code might throw some exceptions or create errors that might look ugly when a user is using the application. In such cases you use exception handling to catch and handle the exception and exit gracefully. You use the try - catch block in Java for exception handling.


How do you throw exception in java?

we do it using the throw keyword.


Which is the base class of exception handling in java?

Thorwable


Write the 3 user defined exception in java?

1. Arithmetic Exception 2. Input Output Exception 3. Number Format Exception


How do you throw exception?

using throws class try, catch block we through the exception