PHP Fatal error: Uncaught exception 'Exception'

后端 未结 3 1425
名媛妹妹
名媛妹妹 2020-12-17 19:25

I\'m playing around with exceptions in PHP. For example, I have a script that reads a $_GET request and loads a file; If the file doesn\'t exists, an new exception should be

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 20:07

    Just adding a bit of extra information here in case someone has the same issue as me.

    I use namespaces in my code and I had a class with a function that throws an Exception.

    However my try/catch code in another class file was completely ignored and the normal PHP error for an uncatched exception was thrown.

    Turned out I forgot to add "use \Exception;" at the top, adding that solved the error.

提交回复
热议问题