CroctException
Learn how to handle errors thrown by the SDK.
This interface is implemented by every exception the SDK throws, so you can catch it to handle any SDK error in a single place.
Operations such as fetchContent and evaluate throw a CroctException when a request fails and no fallback is set. Providing a fallback is the recommended way to keep your application resilient.
Example
This example fails open, falling back to a default when personalization is unavailable:
1234567891011
<?phpuse Croct\Plug\Croct;use Croct\Plug\Exception\CroctException;
$croct = Croct::fromDotenv();
try { $returning = $croct->evaluate('user is returning') === true;} catch (CroctException $error) { $returning = false;}Hierarchy
The CroctException interface extends Throwable, and the SDK throws the following implementations:
| Exception | Thrown when |
|---|---|
| EvaluationException | A query is invalid or cannot be evaluated. |
| ContentException | Content cannot be fetched and no fallback is available. |
| ConfigurationException | The SDK is misconfigured, such as missing credentials or no HTTP client. |