How do I catch an exception in a controller in Laravel?

In my controller I need to test a custom database connection and if that is bad, return an error. The problem is the block is catch

not working ... I am getting an exception that is defined globally in app/start/global.php

.

try {
    DB::connection('test');
} catch (Exception $e) {
    dd('error');
}

      

+3


source to share


1 answer


Laravel handles exceptions, no try / catch needed. You can write a custom exception inside \ App \ Exceptions and customize the content of App \ Exceptions \ handler.php to format the response of any single exception to suit your needs.



+2


source







All Articles