answersLogoWhite

0

What is the use of throws in java?

User Avatar

Anonymous

15y ago
Updated: 8/18/2019

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.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

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.


Why use throw in java in compare try-catch?

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


Can you use pointers in java?

Java does not support Pointers and hence you cannot use it in Java.


What technologies link to Java?

Java is exclusive to surfing the web. Some web sites use Java to embed videos, others use Java for advertisements.


What you use in case of pointer in java?

Java does not have pointers


Does Java Script use the same compiler as Java?

No


What is java 7?

Java 7 is the most current version of Java. Many movies and games use Java.


Which is the best Book to understand JAVA in short?

You can use Head First Java or Java Complete Reference to learn Java.


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


Do you have to use java?

Not usually. There are numerous languages out there with similar functionality. The only time you must use Java is if your employer or client demands that a project be done in Java, or a particular platform requires the use of Java, such as Android OS.


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#?


How do you script a RuneScape bot?

RuneScape bots use Java. Use a Java Binary Code.