Custom exception for business rule
Java
Medium
4 views
Problem Description
Task: create a custom exception InsufficientBalanceException and throw it when withdraw > balance.
Output Format
Return value
Constraints
Keep exception as checked.
Official Solution
static class InsufficientBalanceException extends Exception{}static int withdraw(int bal,int amt) throws InsufficientBalanceException{if(amt>bal) throw new InsufficientBalanceException();return bal-amt;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!