Fixing Error: Unreported Exception InterruptedException

Provided example demonstrates how to do exception pass up the call chain (up the method call chain). For this your method declaration contains a throws InterruptedException.

Alternative approach is to handle exception in the method it occurred: in your case add

try 
{
    Thread.sleep(2000);
} 
catch(InterruptedException e)
{
     // this part is executed when an exception (in this example InterruptedException) occurs
}

After you added try {} catch() {} block, remove "throws InterruptedException" from the method DS.

You can wrap other lines with try {} catch() {} block as required. Read about Java exceptions.

Tags:

Java

Exception