Java: exception-throwing class?
- by HH
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?
Currently, I use initCorrect -dummy var. Exception-style method may be more appropriate.
Simplified Example Error
$ javac ExceptionStatic.java
ExceptionStatic.java:4: '{' expected
public class ExceptionStatic throws Exception{
^
1 error
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);
}
}