I have a class that loads and parse data from XML files in a static initializer like so:
class A {
//static structures to store parsed XML data
public static int num;
...
static {
try {
//load/parse XML data
catch (Exception e) {
throw new RuntimeException("...");
}
}
public static void method1() {
//do some work on data
}
The data loaded by this class is used to load critical data into my application:
class Important {
...
public initCriticalData() {
try {
Class A.method();
catch(java.lang.ExceptionInInitializerError e) {
//notify user of failure to load/parse XMLs and wait for user to close application
}
}
}
It is recommended to not catch fatal errors, but in this situation would it be appropriate to catch an error for notifying the user? Or should I have taken a different direction in my design and have loaded data outside a static initializer? Data needed to be loaded lazily, which is why I went with this approach.