Exception Handling Flashcards

1
Q

What is exception handling?

A

Exception Handling is used to handle RunTime errors that occur in the JVM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the differences between a Checked and Unchecked exception?

A

Checked exceptions extend Throwable, but not RuntimeException or Error classes. UncheckedException extend RuntimeException.
Checked are checked at compile time, unchecked happen at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the finally block in java?

A

Finally block is an optional block that can come with a try/catch block. Finally block is always executed after the execution of a try block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the use of finally block?

A

Finally block is always executed wether an exception occurs or not. It helps in doing the cleanup like Rollback Transaction, Close connection etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Do we always have to put a catch block after a try block?

A

Java does not enforce the rule to put a catch block after a try block. You can write a catch block or a finally block after a try block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What scenarios will a finally block not be executed?

A

If the program exits by calling system.exit() or a fatal error causes the JVM to crash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between throw and throws?

A

We use throw to explicitly throw an exception. We use throws to declare an exception in method definition. A call to throw occurs within a method, throws is just used with method signature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly