UrlNotFoundException
Thrown when attempting to resolve a URL that doesn't exist.
Namespace
JobMetric\Url\Exceptions\UrlNotFoundException
Overview
This exception is thrown when:
- Attempting to resolve a URL that doesn't exist
- URL is not found in the database
When It's Thrown
The exception is thrown when:
- Attempting to resolve a URL that doesn't exist
- URL is not found in the database (active or trashed)
Example
try {
$model = Url::resolveActiveByFullUrl('/non-existent-path');
if (!$model) {
throw new UrlNotFoundException();
}
} catch (UrlNotFoundException $e) {
// Handle not found
}
Handling
try {
$model = Url::resolveActiveByFullUrl($fullUrl);
if (!$model) {
throw new UrlNotFoundException();
}
} catch (UrlNotFoundException $e) {
abort(404, 'URL not found');
}
Error Message
The exception message is translated using url::base.exceptions.not_found:
trans('url::base.exceptions.not_found')
Prevention
Check for null before throwing:
$model = Url::resolveActiveByFullUrl($fullUrl);
if (!$model) {
abort(404, 'URL not found');
}
Related Documentation
- Url Model - Model that may throw this exception