How do I consolidate errors when catching? (IE. single catch clause)
Hey all,
I'm trying to create a simple exception handler class. I'm trying to make calls to
a database and run a querry but exceptions a, b, c, and d must be caught.
The only way I know to do this is with multiple catch statements like this.try{
connectDatabase();
runQuery();
}
catch(SQLException err){
system.out.println(err);
}
catch(IllegalAccessException err){
system.out.println(err);
}
catch(ClassNotFoundException err){
system.out.println(err);
}
catch(InstantiationException err){
system.out.println(err);
}
This gets very redundant in my code because all I want to do is call two methods
and I end up writing 20 lines of code. I was told that I can create a custom exception
object that somehow contains exceptions a, b, c, and d, but I do not know how to do this.
I would like to be able to do something like thistry{
connectDatabase();
runQuery();}
catch(GeneralError err){
system.out.println(err);}
Can someone please tell me what I will need in my GeneralError class?
So far, I've come as far as extending the Exception class.
Thanks for any help

