Why doesn't catching Exception catch RuntimeException?

后端 未结 5 726
眼角桃花
眼角桃花 2020-12-08 00:05

This is very odd to me. RuntimeException inherits from Exception, which inherits from Throwable.

catch(Exception exc)          


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 00:45

    catch (Exception ex) { ... }
    

    WILL catch RuntimeException.

    Whatever you put in catch block will be caught as well as the subclasses of it.

提交回复
热议问题