在Exception层次结构中,RuntimeException是未经检查的Exception的子类,但是如果我们使用Exception,则将其视为已检查的Exception为何?
From the Oracle Java documentation :
Runtime exceptions can occur anywhere in a program, and in a typical one they can be very numerous. Having to add runtime exceptions in every method declaration would reduce a program's clarity. Thus, the compiler does not require that you catch or specify runtime exceptions (although you can).
So they added RuntimeExceptions to deal with common run-time problems, without the hassle of catching-or-throwing every single time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.