Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

example of throws clause in method

import java.io.*;
class ThrowExample { 
  void myMethod(int num)throws IOException, ClassNotFoundException{ 
     if(num==1)
        throw new IOException("IOException Occurred");
     else
        throw new ClassNotFoundException("ClassNotFoundException");
  } 
} 

public class Example1{ 
  public static void main(String args[]){ 
   try{ 
     ThrowExample obj=new ThrowExample(); 
     obj.myMethod(1); 
   }catch(Exception ex){
     System.out.println(ex);
    } 
  }
}
Source by beginnersbook.com #
 
PREVIOUS NEXT
Tagged: #throws #clause #method
ADD COMMENT
Topic
Name
5+3 =