1 If your code does not catch a thrown exception what happen

1) If your code does not catch a thrown exception, what happens?

2) The method: String.changeString(s) throws a NullPointerException when the string, s, passed to it contains a null value. Give the try-catch clause coded in methods that invoke it to output “you must make an entry” when s is null.

3) Can your code throw an object in an exception class that is part of the Java API?

Solution

Question 1:

Answer: If out cde does not catch a thrown exception then program will terminate abnormally at run time.

Question 2:

Answer:

   public void changeString(String s){
       try{
           if(s == null){
               throw new NullPointerException();
           }
       }
       catch(NullPointerException e){
           System.out.println(\"you must make an entry\");
       }
   }

Question 3:

Answer: Yes we can throw an object in an exception class that is part of java API

1) If your code does not catch a thrown exception, what happens? 2) The method: String.changeString(s) throws a NullPointerException when the string, s, passed

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site