Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions what is difference between throw and throws
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


prakashrumma
what is difference between throw and throws
1 Answer(s)      2 years and 7 months ago
Posted in : Java Interview Questions


what is difference between throw and throws


Advertisement
View Answers

May 31, 2012 at 1:25 PM


Difference between throw and throws keywords

Whenever we want to force an exception then we use throw keyword. the throw keyword (note the singular form) is used to force an exception. It can also pass a custom message to your exception handling module. Moreover 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. For instance in the above example we have used -

throw new MyException ("can't be divided by zero");

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. We can also use throws clause on the surrounding method instead of try and catch exception handler. For instance in the above given program we have used the following clause which will pass the error up to the next level -

static int  divide(int first,int second) throws MyException{


Related Tutorials/Questions & Answers:
Difference between throw and throws in java.
Difference between throw and throws in java. Throws and throw both.... Throws can be declared with multiple Exceptions separated with comma. Throw...()throws IOException { throw new IOException("Hello"); } "
Java throw and throws
Java throw and throws  What is the difference between throw and throws
Advertisements
Java throw ,throws
Java throw ,throws  What is the difference between throw and throws
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  What is the difference between Throw and Throws
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  what is the difference between Throw,Throws and Try&Catch
What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks
what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements
what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements
What is the difference between hibernate and spring
What is the difference between hibernate and spring  Hi, What is the difference between hibernate and spring. Thanks
what is the difference between pop and oop
what is the difference between pop and oop  what is the difference between pop and oop
what is the Difference between weblogic and jboss?
what is the Difference between weblogic and jboss?  what is the Difference between weblogic and jboss
What is the difference between $message and $$message?
What is the difference between $message and $$message?  What is the difference between $message and $$message
What is difference between a PROCEDURE & FUNCTION ?
What is difference between a PROCEDURE & FUNCTION ?  What is difference between a PROCEDURE & FUNCTION
What is the difference between PHP4 and PHP5?
What is the difference between PHP4 and PHP5?  What is the difference between PHP4 and PHP5
What is the difference between a constructor and a method?
What is the difference between a constructor and a method?  Hi, What is the difference between a constructor and a method?   Hi, I have found a good link of Java program related to difference between constructor
What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Read Here Thanks
What is the difference between a JDK and a JVM?
What is the difference between a JDK and a JVM?  Hi, What is the difference between a JDK and a JVM? Thanks,   Hi, JDK is stand... to compile your source files using a JVM. For more difference between JDK and JVM
What is difference between Path and Classpath?
What is difference between Path and Classpath?   hi What is difference between Path and Classpath? thanks   Hi, The Path & Classpath are used for operating system level environment variales. We mostly use Path
What is difference between TRUNCATE & DELETE
What is difference between TRUNCATE & DELETE   What is difference between TRUNCATE & DELETE?   Hi, The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows
What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Difference: 1) Java is a Object Oriented programming language developed by Sun Microsystems
What is the difference between JSF, Servlet and JSP?
What is the difference between JSF, Servlet and JSP?  What is the difference between JSF, Servlet and JSP
What is difference between singleton and prototype bean?
What is difference between singleton and prototype bean?  Hi, What is difference between singleton and prototype bean? Thanks
What’s the difference between load() and get()?
What?s the difference between load() and get()?   Hi, What?s the difference between load() and get()? thanks
what is the difference between distributed application and web application?
what is the difference between distributed application and web application?  what is the difference between distributed application and web application
What’s the difference between include and require?
What?s the difference between include and require?  What?s the difference between include and require
What are the difference between abstract class and interface?
What are the difference between abstract class and interface?  What are the difference between abstract class and interface
What is the difference between the functions unlink and unset?
What is the difference between the functions unlink and unset?  What is the difference between the functions unlink and unset
What is the difference between ereg_replace() and eregi_replace()?
What is the difference between ereg_replace() and eregi_replace()?  What is the difference between eregreplace() and eregireplace
what is difference between objectan primitive? - Java Beginners
what is difference between objectan primitive?  whatis difference between object and primitive
What are difference between Bean Factory and Application Context ?
What are difference between Bean Factory and Application Context ?  Hi, What are difference between Bean Factory and Application Context
What is the difference between the Boolean & operator and the && operator?
What is the difference between the Boolean & operator and the && operator?   Hello, What is the difference between the Boolean & operator and the && operator? thanks
Advertisements
 

 

 

DMCA.com