The following trycatch has code to explicitly handle any Ill

The following try/catch has code to explicitly handle any

    IllegalArgumentException thrown. Show the modified code that

    will also catch any other type of exception that could be thrown

    by code called within the try block.

    try

    {

      ... methods called here ...

      ...

    }

    catch (IllegalArgumentException e)

    {

      ... code to handle IllegalArgumentException ...

    }

Solution

Program:

import java.io.*;
class Try
{
public static void main(String args[])
{
try {
throw new IllegalArgumentException(\"Throw an IllegalArgumentException\"); //IllegalArgumentException method
} catch(IllegalArgumentException e) {
System.out.println(\"Caught an IllegalArgumentException...\" + e.getMessage());
}
}
}

Output:

Caught an IllegalArgumentException...Throw an IllegalArgumentException

The following try/catch has code to explicitly handle any IllegalArgumentException thrown. Show the modified code that will also catch any other type of excepti

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site