Safe divide

Easy
4 views 23 Jan 2026
Task: divide a by b and throw ArithmeticException when b is 0....

Validate positive input

Easy
6 views 23 Jan 2026
Task: if x is negative, throw IllegalArgumentException. Else return x....

Parse int with fallback

Easy
7 views 23 Jan 2026
Task: parse integer from string; if invalid, return fallback value....

Array access safe read

Easy
5 views 23 Jan 2026
Task: return a[index] if valid else throw IndexOutOfBoundsException....

Ensure object not null

Easy
4 views 23 Jan 2026
Task: if obj is null throw NullPointerException else return it....

Try-with-resources style (concept)

Medium
5 views 23 Jan 2026
Task: show a method that closes a Closeable safely in finally without hiding original exception....

Custom exception for business rule

Medium
4 views 23 Jan 2026
Task: create a custom exception InsufficientBalanceException and throw it when withdraw > balance....

Validate age range

Medium
5 views 23 Jan 2026
Task: age must be 1..120. If not, throw IllegalArgumentException....

Convert checked to unchecked

Medium
6 views 23 Jan 2026
Task: wrap IOException into RuntimeException and rethrow....

Multiple validations with one throw

Medium
7 views 23 Jan 2026
Task: validate (nameLength > 0) and (score between 0..100). Throw IllegalArgumentException if any fails....

Transactional-like update with rollback

Hard
5 views 23 Jan 2026
Task: update two array positions. If any index is invalid, keep array unchanged and throw exception....

Retry operation 3 times

Hard
7 views 23 Jan 2026
Task: call a risky operation and retry up to 3 times on exception. If still fails, throw last exception....

Validate sorted input or fail fast

Hard
8 views 23 Jan 2026
Task: if array is not sorted, throw IllegalStateException. Else return true....

Propagate cause chain

Hard
7 views 23 Jan 2026
Task: wrap exception with cause and rethrow as RuntimeException keeping original cause....

Fail-safe resource close with primary exception

Hard
5 views 23 Jan 2026
Task: simulate primary exception and also close exception; ensure primary is thrown....