I have tried to isolate this problem (to produce it outside my app), but I can't.
try {
$has_cache = Cache::has($cache_key);
}
catch (DecryptException $e) {
echo "No biggie";
exit;
}
I also tried with a catch (Exception $e)
, the same thing happens.
Using this code, I get a DecryptException in the second line. How can this happen, it's in the try block?
Like I said, I tried to do the same on a clean project, but there it caught the exception, so I'm asking where could I have messed something up.
If your application is namespaced, you would need to use
catch(\Exception $e);
// or preferably
catch(\RuntimeException $e);
likewise, I think the DecryptException
you are trying to catch is namespaced in Illuminate\Encryption
so you'd need
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 (apparently they are not sure themselves), so it is in no way stable and probably not the best choice for production.
For laravel 5.1 you should write(generally at start of the file with other use statements):
use Illuminate\Contracts\Encryption\DecryptException;
Before catch statement:
try {
$data = \Crypt::decrypt($key);
} catch (DecryptException $e) {
echo 'caught exception';
exit();
}
Ref: https://laravel.com/docs/5.1/encryption - under "Decrypting A Value"
May be helpful for others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With