Laravel 4 can't catch an exception

I tried to isolate this problem (to create it outside of my application), but I cannot.

try { $has_cache = Cache::has($cache_key); } catch (DecryptException $e) { echo "No biggie"; exit; } 

I also tried using catch (Exception $e) , the same thing happens.

Using this code, I get a DecryptException in the second line. How can this happen, is this in a try block?

As I said, I tried to do the same in a clean project, but there he fell into the exception, so I ask where I could ruin something.

+7
source share
2 answers

If your application has a namespace, you will need to use

 catch(\Exception $e); // or preferably catch(\RuntimeException $e); 

Similarly, I think the DecryptException you are trying to catch is in the Illuminate\Encryption folder, so you need to

 catch(\Illuminate\Encryption\DecryptException) // or use "use" somewhere before the try/catch use \Illuminate\Encryption\DecryptException 

Keep in mind that Laravel 4 is still alpha or pre-beta strong> (apparently, they are not sure for themselves), so it is in no way stable and probably not the best choice for production.

+24
source

For laravel 5.1 you should write (usually when you run a file with other usage operations):

 use Illuminate\Contracts\Encryption\DecryptException; 

Before the catch statement:

 try { $data = \Crypt::decrypt($key); } catch (DecryptException $e) { echo 'caught exception'; exit(); } 

Link: https://laravel.com/docs/5.1/encryption - in the section "Decryption of the value"

May be helpful to others.

+2
source

All Articles