Difference Between throw and throws Keyword in Java

0
23
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Difference Between throw and throws Keyword in JavaDifference Between throw and throws Keyword in Java
In my previous post on java , I have explained about throw keyword here and throws keyword in ja. Furthermore I will discuss the difference between the two keywords in java.

Besides the both serve different purpose. The difference table is given below:

Sl No throw throws
1 throw is used to create a new Exception object and throw it It is used in method definition to declare that a risky method is being called and

the method may throw the specified Exception.

2 Using throw we can only throw one Exception type using throws we can declare multiple Exceptions
3 Example-throw new IOException (“Can not open Connection”); Example- throws IOException,ArrayIndexBoudException
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here