I would have another question I cannot find answer on. I know that the order of catch blocks is from the most derived to the most general.
But I do not understand why I can have this (why does this order work? formatException is derived from Exception so its more general, right?)
catch(formatException)
//this is derived from Exception
catch(OutoFMemoryException)
// this is derived from ArithmeticException whic is derived from Exception
Not nescessary, even though
OverflowExceptionderives fromArithmeticExceptiontheir most common denominator isException.You can see it as somekind of tree structure, where
FormatExceptionandOverflowExceptionis on different sides of the tree. IfOverflowExceptioninherited fromFormatExceptionthe situation would be different, but that is not the case.Also, you can have them in different order but it is no point since if you have a more general exception first it will catch every exception below it as well.