This Laravel package adds native-like @try, @catch, @finally, and @endtry directives to Blade templates, allowing you to handle exceptions gracefully inside your views.
You no longer need to clutter your controllers for simple error handling in views — this package provides a clean, elegant syntax for try-catch-finally in Blade.
Compatible with Laravel 5.8 through 12 and PHP 7.1+.
You can install the package via Composer:
composer require azmolla/blade-try-catchThe package auto-registers the service provider via Laravel's package discovery. No manual provider registration needed.
Use the directives in any Blade view:
@try
{{-- Code that may throw an exception --}}
{{ riskyFunction() }}
@catch(\Exception $e)
{{-- Handle the exception --}}
<div class="error">Error: {{ $e->getMessage() }}</div>
@finally
{{-- Code that always runs --}}
<p>Cleanup completed.</p>
@endtryThis package uses Pest for testing.
To run tests locally:
composer testMake sure to install development dependencies before running tests:
composer install --devContributions, issues, and feature requests are welcome!
- Fork the repo
- Create your feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature/my-feature) - Open a pull request
Please ensure your code passes existing tests and write new tests if applicable.
MIT © 2025 Abiruzzaman Molla