Practice Exception Handling in Java

Handle errors gracefully using try-catch, throw, and custom exceptions.

Work through 24 exercises with starter code, expected output, test cases, and hints.

Exception Handling exercises

  1. Basic Try-Catch Java exercise — Handle a simple exception
  2. Multiple Catch Blocks Java exercise — Handle different exception types
  3. Using Finally Block Java exercise — Execute cleanup code with finally
  4. Throwing Exceptions Java exercise — Manually throw an exception
  5. Using Throws Clause Java exercise — Declare exceptions in method signature
  6. Try-With-Resources Java exercise — Automatic resource management
  7. Custom Exception Class Java exercise — Create and use custom exception
  8. Input Validation with Exceptions Java exercise — Validate user input using exceptions
  9. Exception Chaining Java exercise — Chain exceptions to preserve cause
  10. Retry with Exceptions Java exercise — Implement retry logic for failures
  11. Exception Propagation Java exercise — Understand exception propagation through call stack
  12. Age Range Validator Java exercise — Validate age is within acceptable range
  13. Password Validation Java exercise — Validate password against multiple rules
  14. Null Handling Java exercise — Handle NullPointerException gracefully
  15. Resource Cleanup Pattern Java exercise — Ensure resources are cleaned up
  16. Exception Logging Java exercise — Log exception details properly
  17. Retry Mechanism Java exercise — Implement automatic retry on failure
  18. Age Input Validation with Exceptions Java exercise — Validate user input using exceptions
  19. Aggregate Multiple Exceptions Java exercise — Collect and report multiple validation errors
  20. Graceful Degradation Java exercise — Provide fallback when operation fails
  21. Exception Chaining Java exercise — Chain exceptions to preserve root cause
  22. Custom AutoCloseable Java exercise — Create a resource that auto-closes
  23. Suppressed Exceptions Java exercise — Handle exceptions during close()
  24. Validation with Exceptions Java exercise — Validate input and throw appropriate exceptions

Browse the complete Java practice path · Open the online Java compiler