Java Tutorial/Statement Control/throws signature

Материал из Java эксперт
Перейти к: навигация, поиск

throws Exception from method

   <source lang="java">

class ThrowsDemo {

 static void throwOne() throws IllegalAccessException {
   System.out.println("Inside throwOne.");
   throw new IllegalAccessException("demo");
 }
 public static void main(String args[]) {
   try {
     throwOne();
   } catch (IllegalAccessException e) {
     System.out.println("Caught " + e);
   }
 }

}</source>