1public void doChangePin(int oldPin, int pin) throws Exception { //need to add throws followed by exception name
2 if (oldPin == pinCode) {
3 pinCode = pin;
4 } else {
5 throw new Exception("some message"); //throwing the exception by creating its new object
6 }
7 }
1Throws keyword used for handling exceptions.
2 Where do you use it? Methods signature.
3 If you want to handling right away in selenium or Api use “throws” keyword.
4Throw is creating an exception. Basically there are doing opposite.
5Where do you use it? We use it with in the block.
1Generally JVM throws the exception and
2we handle the exceptions by
3using try catch block. But there are
4situations where we have to throw
5userdefined exceptions or runtime exceptions.
6 In such case we use throw keyword
7to throw exception explicitly.
8
9 Syntax : throw throwableInstance;
10
11