Exception Hierarchy
All SDK exceptions extendLaw4Devs\Exceptions\Law4DevsException, which itself extends \RuntimeException.
statusCode property:
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:
Network Errors
Connection failures (timeout, DNS, SSL) throwLaw4DevsException with statusCode of null:
Best Practices
- Always catch
Law4DevsExceptionas a fallback to handle unexpected errors - Check
$e->statusCodeto distinguish network errors (null) from API errors - Wrap
iter()loops in a try/catch — exceptions can occur mid-iteration if a page request fails - For batch processing, implement a retry strategy at the application level if you need finer control than the built-in retry
