1

I have a PHP file that extends the Exception class.

namespace App\CustomException;

class FileException extends Exception {

    public function __construct($name) {
        parent::construct($name);
    }
}

I get a fatal error: Fatal error: Class 'App\CustomException\Exception on the line for the class that extends Exception.

I want to use a namespace for my custom exception messages so that I can import them easily in a another file, like use App\CustomException.

Why am I getting an error and how do I fix this? I don't get an error when I remove extend Exception, so I'm guessing this has something to do with the parent class.

1 Answer 1

8

Try:

class MyException extends \Exception {}
// Add / before Exception ;)
Sign up to request clarification or add additional context in comments.

2 Comments

I actually did try that after googling...and it did not work. ...I just tried it again, and it worked! What happened?
I don't know... If you use cache or sync(ftp,...)... perhaps you've lost your change...

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.