Exception Hierarchy
All SDK exceptions extendeu.law4devs.sdk.exceptions.Law4DevsException, which itself extends RuntimeException.
getStatusCode() method:
Catching Specific Errors
Automatic Retry
The SDK automatically retries on429 Too Many Requests and 5xx Server Error responses using exponential backoff:
After
maxRetries (default 3) attempts, the exception is re-thrown.
To disable retries, set maxRetries(0):
NotFoundError (404) and ValidationError (400) are never retried — they represent client errors that will not resolve by retrying.Network Errors
Connection failures (timeout, DNS, SSL) throwLaw4DevsException with a message describing the failure:
Errors in iter() Loops
Exceptions can be thrown mid-iteration if a page request fails. Wrap iter() loops in a try/catch:
Best Practices
- Always catch
Law4DevsExceptionas a fallback to handle unexpected errors - Wrap
iter()loops in a try/catch — exceptions can occur mid-iteration if a page request fails - Use
getStatusCode()to distinguish error types when handlingLaw4DevsExceptiongenerically - For batch processing, implement a retry strategy at the application level if you need finer control than the built-in retry
- Prefer specific exception types (
NotFoundError,RateLimitError) over the base class for cleaner error handling
