Netty,
In both the cases you have to use MyException instead of IOException. The reason being you always try to catch Exception that is being thrown. According to your code doStuff() throws MyException. So that should be the one
you should be catching. Keep in mind that MyException extends Exception and not IOException( IOException being a subclass of Exception). So you cannot catch IOException in the places where MyException is caught. The compiler complains that IOException is never thrown in scope. You could otherwise say something like
or
This is valid because MyException is subclass of Exception and not IOException. Hope this clears your doubt.