Question: Java What, if anything, is wrong with the following Java method that uses exceptions? If there is something wrong with it, what is the most
Java

What, if anything, is wrong with the following Java method that uses exceptions? If there is something wrong with it, what is the most natural way of fixing it? public void g(String s) { if (s == null) { NullPointerException e = new NullPointerException(Invalid Input); throw e; } } Nothing wrong with the method Method declaration needs a throws clause: public void g (String s) throws NullFcinterException {... Method body needs a try/catch: if (s == null) { NullPointerExceptione = new NullFcinterException(Invalid Input); try { throw e; } catch (NullFcinterException e1) { e1.printStacfcTrace() ; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
