Snuze Exception classes


The classes described here are in the \snuze\Exception namespace.

Snuze exception overview

When Snuze encounters a problem, it throws an exception. The exceptions raised by Snuze are descendants of SnuzeException. This is a special type of exception that copies its error message to the log file (assuming one is enabled), even if you catch it. This allows you to swallow minor exceptions while your script keeps running, then scan the log file occasionally to see if anything funky is going on.

There's one, uh, exception to this rule. If SnuzeFactory can't build a Snuze object, it'll throw a plain SPL \RuntimeException or \UnexpectedValueException, and no logging will occur.

Devising an error handling strategy is left up to you. Some exceptions are less severe than others; you might just want to catch them and move on. Others indicate a dire and unrecoverable problem that should result in your script terminating. Snuze itself never calls exit; it can only interrupt execution if you don't handle its exceptions.

The SnuzeException class

The \snuze\Exception\SnuzeException class is the ancestor of all other exception types listed below. It does a few things above and beyond a regular SPL Exception:

  1. Its code property e.g. $ex->getCode() is forced to an integer type, despite the best efforts of certain PHP extensions;

  2. When thrown by a SnuzeObject subtype, the short class name and Snuze internal identifier of the SnuzeObject will be prepended to the error message to assist with troubleshooting;

  3. The error message will be logged to the Snuze log file, if one is enabled.

The ArgumentException class

A \snuze\Exception\ArgumentException is thrown when a Snuze method encounters an argument it either wasn't expecting or can't handle. For example, calling fetchSubreddit('t-e-s-t') will throw an ArgumentException, because the specified subreddit name is invalid.

The AuthenticationException class

A \snuze\Exception\AuthenticationException is thrown when Snuze can't authenticate with the API server, or receives a "401 Unauthorized" response from the API server after making a request. This may indicate a problem with the Reddit credentials Snuze is configured to use.

The ForbiddenException class

A \snuze\Exception\ForbiddenException is thrown when Snuze receives a "403 Forbidden" response from the API server. The most frequent cause is attempting to fetch something that the authenticated user doesn't have permission to access, like a private or quarantined subreddit.

The NotFoundException class

A \snuze\Exception\NotFoundException is thrown when Snuze receives a "404 Not Found" response from the API server. The most frequent cause is attempting to fetch something that's no longer available, like a deleted link or a banned subreddit.

The PersistenceException class

A \snuze\Exception\PersistenceException is thrown when Snuze encounters a problem related to a storage provider. In the MySQL storage provider, this often indicates a database column width issue; if the message mentions data truncation, please file a bug report.

The RateLimitException class

A \snuze\Exception\RateLimitException is thrown when your script exceeds the Reddit API rate limit and you have the autosleep option disabled.

The RuntimeException class

A \snuze\Exception\RuntimeException is a catch-all exception. It's thrown when Snuze has a problem that isn't suited to a more specific exception type.

The ServerErrorException class

A \snuze\Exception\ServerErrorException is thrown when Snuze receives a 500-series HTTP response code from the API server. This indicates a server problem on Reddit's end. It's suggested that you catch these and sleep() for awhile to give Reddit time to recover.