Explanation:The method demo declares using throws clause that it can throw an exception of
IOException class type. In the main inside try block, the demo method is called. As the method can
throw an exception, it is placed it in the try block. The method when called throws an exception of type
IOException as follows:
new IOException("demo of throws");
The exception object thrown is caught by the catch block and the program terminates gracefully:
OUTPUT:
Exception Caught
demo of throws
import java.io.*;
class JPS11
{
static void demo() throws IOException
{
throw new IOException("demo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.