I have a few Exception classes that I built (which currently don't inherit from any class). I want to do a "try" and "catch" and in the catch print the error message which relates to the specific Exception class that has been thrown. Is there a possible way to do
try(something){
}
catch(){
System.out.println(error.printMsg());
}
and that according to the excpetion, it would print the msg that related to the class?
Edit: I will refine my question, in try and catch, can be thrown a few possible Exception classes that I built, I want instead of doing :
catch(Error1){
System.err.println(Error1.ERROR_MSG);
}
catch(Error2){
System.err.println(Error2.ERROR_MSG);
}
to do :
catch(ERROR1 | ERROR2){
System.out.println(GenarlError.ERROR_MSG)
// maybe to do a class that all the Excpetion will inhirt from, and somehow
//do upcasting,or something like that (but If I will do upcasting it would
//print the message or the right class?
}