0

I'm trying to throw an exception inside a try ... catch block but for some reason I get an error Fatal error: Uncaught Exception. A handler is assigned, but why doesn't it fire?

try {
   if (!isset($_SESSION["Authorized"])){
      throw new Exception();
   } 
} catch (Exception $e){
   die('No access');
}

Clarification, I was surprised to find that the error only occurs when debugging Visual Studio code using Xdebug. If debug mode is off, no error occurs. Why so?

5
  • 1
    The above code seems to work just fine? 3v4l.org/acSub Commented Dec 2, 2019 at 6:18
  • The error only occurs when debugging in Visual Studio Code. Fixed description Commented Dec 2, 2019 at 6:26
  • In result - help this stackoverflow.com/questions/44538157/… Commented Dec 2, 2019 at 6:37
  • Why are you using exceptions here at all? Why not just an if-statement? You would get the exact same result: if (!isset($_SESSION[...])) { die('No access'); }. Commented Dec 2, 2019 at 6:38
  • This code work fine. I checked. Commented Dec 2, 2019 at 8:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.