When I try to write this code :
catch (Exception | OutOfMemoryError| NumberFormatException| SQLException| IOException e){
}
I get the error: "The exception NumberFormatException is already caught by the alternative Exception" I understand it great and from first thinking it's make sense because Exception is the general one. but when I write this code:
catch (Exception | OutOfMemoryError e){
}
It works without any problems so now I start to get confused why don't I get the previous error. Is OutOfMemmoryError will catch things that Exception won't catch? If I Want to make catch that will include all of exceptions and errors possible what should i write? I just understood that this:
catch (Exception e){
}
won't catch for me all the exceptions and errors so what will do it?