小编Psy*_*yAp的帖子

Why does the compiler allow throws when the method will never throw the Exception

I am wondering why the java compiler allows throws in the method declaration when the method will never throw the Exception. Because "throws" is a way of handling the exception (telling the caller to handle it).

Since there are two ways of handling exception (throws & try/catch). In a try/catch, it doesn't allow the catch of an exception not thrown in the try block but it allows a throws in a method that does may not throw the exception.

private …
Run Code Online (Sandbox Code Playgroud)

java checked-exceptions

18
推荐指数
2
解决办法
1693
查看次数

标签 统计

checked-exceptions ×1

java ×1