Hi , the exception in the below code, how can I catch the exception it without the program crashing
public void setFirstName(String firstName){ if(firstName.length() < 2){ throw new IllegalArgumentException("NAME LENGTH IS TOO SHORT! "); } this.firstName = firstName; }
I want to catch it in the tester class
public class Car_Tester{ public static void main (String[] args){ CarType1 c1 = new CarType1("B.M.W","Series 7",100,51000,true); System.out.println(c1.toString()); c1.move(); try{ setPrice(int price); } catch(IllegalArgumentException e) { System.out.println(" error"); } }
Is it possible to do this? my solution above didn't work.
thanks