Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Java 10 questions

Java Exception Handling & Debugging

Understand Java exception hierarchies. Learn throw/throws declaration, checked vs unchecked exceptions, try-with-resources, and custom exceptions.

More Java
Interview questions 1–10 of 10
1

What is the difference between checked and unchecked exceptions in Java?

TypeChecked atMust be declared/caught?ExamplesChecked exceptionCompile timeYes - or method must declare 'throw...

Read answer →
2

How does try-catch-finally work in Java, and when does finally NOT execute?

public int divide(int a, int b) { try { return a / b; } catch (ArithmeticException e) {...

Read answer →
3

How do you create and throw a custom exception in Java?

Custom exceptions are created by extending Exception (for checked) or RuntimeException (for unchecked), lettin...

Read answer →
4

What is try-with-resources and why is it preferred over manual resource closing?

try-with-resources automatically closes any resource that implements AutoCloseable when the try block finishes...

Read answer →
5

What is the difference between throw and throws in Java?

KeywordUsed forLocationNumber allowedthrowActually throwing an exception instanceInside a method bodyOne excep...

Read answer →
6

What is exception chaining in Java and what does getCause() do?

Exception chaining preserves the original exception when wrapping it in a new one, using getCause() to trace b...

Read answer →
7

What happens if an exception is thrown inside a finally block?

An exception thrown in finally SUPPRESSES any exception from the try or catch block - only the finally block's...

Read answer →
8

What is a StackOverflowError vs an OutOfMemoryError in Java?

ErrorCauseCommon triggerStackOverflowErrorCall stack exceeds its maximum sizeInfinite or excessively deep recu...

Read answer →
9

What are best practices for logging and debugging exceptions in production Java applications?

PracticeWhy it mattersUse a logging framework (SLF4J, Log4j), not System.outConfigurable levels, output destin...

Read answer →
10

Can overriding methods change the checked exceptions declared by the parent method?

Java restricts what checked exceptions an overriding method can declare - it can throw the SAME, FEWER, or MOR...

Read answer →