0
What is the difference between throw and throws?
throw and throws are the keyword
4 Respostas
+ 6
Please visit following link
http://www.javatpoint.com/difference-between-throw-and-throws-in-java
+ 1
public class A {
public void testA
throws Exception ( ){
}
public void testB ( ) {
throw new Exception ( ) ;
}
public static void main ( String [ ] args ) {
A a = new A ( ) ;
// a.testA ( ) ; // compile error.
try {
a.testA ( ) ;
// the method must be inside the try scope.
catch ( Exception e ) {
e.printStackTrace ( ) ;
}
}
}
+ 1
you use throw when you want to throw an execption as statement, you use throws when you mark a method that may throw an execption for warning user to handle that exception witg try and catch
0
Thx. The answers helped me too!