
I thought checked-exceptions were only exceptions that extend java.lang.Exception but do not extend java.lang.RuntimeException.
Moderator: admin
For the purposes of compile-time checking of exceptions, Throwable and any subclass of Throwable that is not also a subclass of either RuntimeException or Error are regarded as checked exceptions.
Code: Select all
class DogEx extends Exception {}
class CatEx extends Exception {}
public class Foo{
public static void main(String[] args) throws CatEx{
try{
throw new DogEx();
}
catch(DogEx e){
throw new DogEx();
}
finally{
throw new CatEx();
}
}
}
Code: Select all
void m1() throws Exception {}
Code: Select all
try {} catch (Exception e) {}
Code: Select all
try {} catch (java.io.IOException e) {}
Thanks. I also find output prints Done followed by exception.The words "There is nothing wrong with the code.." is a bit misleading as it sometimes
imply that it will compile and run with no trouble. Luckily no other answer seems correct... but
this question eats away a few minutes of your time looking for "Done.. followed by exception.."
or thinking that you might have got it wrong. cheers
throw e; => is in the method signature,and the calling method should handle (throw or catch);Mikhail Volkov wrote: ↑Sun Aug 04, 2019 3:39 amabout }catch(SomeThrowable e){
The same example:
try {...}
catch (Exception e) {
throw new Exception(); - Unhandled exception. I understand this.
but
throw e; - it is ok. Why???
}
Users browsing this forum: No registered users and 3 guests