Selenium and Java

Friday, 26 June 2015

Java- Throw, Throws, Throwable

Java- Throw, Throws, Throwable

Throw:

throw is a keyword in java which is used to throw an exception manually. Using throw keyword, you can throw an exception from any method or block. But, that exception must be of type java.lang.Throwable class or it’s sub classes. Below example shows how to throw an exception using throw keyword.

class ThrowAndThrowsExample
{
 void method() throws Exception
 {
  Exception e = new Exception();

  throw e;            //throwing an exception using 'throw'
 }
}

No comments:

Post a Comment