Task: call a risky operation and retry up to 3 times on exception. If still fails, throw last exception.
A method call that may throw an exception (risky operation).
If succeeds within 3 tries → print "Success"
If fails 3 times → throw the last exception
• Retry maximum 3 times
• If still failing, rethrow the last exception
We attempt the risky operation up to 3 times.
If it succeeds, stop retrying.
If it fails all 3 times, throw the last exception.
1.Initialize attempt = 0.
2.Initialize Exception lastException = null.
3.While attempt < 3:
• Try to perform risky operation.
• If success → return.
• If exception occurs:
• Store exception in lastException.
• Increment attempt.
4.After loop ends:
• Throw lastException.