title: Java: exception-throwing class?
body: <p>I have classes DirReader and Search. The search uses DirReader. I want the search to know when DirReader throws exception. So how can I have class throwing exception?</p>
  
  <p>Currently, I use initCorrect -dummy var. Exception-style method may be more appropriate.</p>
  
  <p><strong>Simplified Example Error</strong></p>
  
  <pre><code>$ javac ExceptionStatic.java 
  ExceptionStatic.java:4: '{' expected
  public class ExceptionStatic throws Exception{
                              ^
  1 error
  </code></pre>
  
  <p><strong>Code</strong> </p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  // THIS PART NEEDS TO BE FIXED:
  public class ExceptionStatic throws Exception{
  
      private static boolean initCorrect = false;
  
      public static String hello;
      static{
          try{
              hello = "hallo";
  
              //some other conditionals in real code
              if( true) throw new Exception();
  
              initCorrect=true;
          }catch(Exception e){
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args){
          if(initCorrect)
              System.out.println(hello);
      }
  }
  </code></pre>