Why would we manually throw an exception? When an exception is to be handled which are not java class library, a user defined exception can be thrown. An exception can be thrown explicitly, when a condition is met. In other words, in a situation where an exception is predicted by the developers, then it can be explicitly thrown. The key word ‘throw’ is used followed by the object of the exception and it accepts only one parameter.
|