220k views
5 votes
What's a checked exception?

A
One that the Java class library already checks for, so our programs don't have to worry about checked exceptions.

B
One that the program must check because the compiler can't check it.

C
One that the compiler can check to make sure the program handles it.

D
One that the operating system checks, evaluates, and corrects.

User Jon Haddad
by
6.1k points

2 Answers

3 votes

Answer:

The correct answer is C)

Step-by-step explanation:

Within Java, a checked exception is one that is checked by the compiler.

When a code within a method generates a checked exception, one of two things must happen:

a) the method should take care of the exception or

b) it should indicate the exception using throws keyword.

Cheers

User Taylor Huston
by
6.0k points
6 votes

Answer:

The answer is option A "One that the Java class library already checks for, so our programs don't have to worry about checked exceptions"

Step-by-step explanation:

A checked exception is a sort of special case that should be either gotten or proclaimed in the method in which it is declared.

In the Java class chain of importance, a special case is a checked exception in the event that it acquires from java.lang.Throwable, however not from java.lang.RuntimeException or java.lang.Error. All the application or business rationale exceptions should be checked special cases.

It is conceivable that a strategy proclaims that it can toss a special case, however it doesn't. In any case, the guest needs to manage it. The checked exception announcement has a domino impact. Any strategies that will utilize the past strategy will likewise need to deal with the checked exception, etc.

So the compiler for the Java programming language checks, at gather time, that a program contains overseers for all application exceptions, by examining every method body. In the event that, by executing the method body, an exception can be tossed to the guest, that special case should be announced. How does the compiler know whether a method body can toss an exception? That is simple. Inside the method body, there are calls to different strategies; the compiler takes a gander at every one of their strategy signature, what exceptions they proclaimed to declare.

User Katafalkas
by
6.0k points