Curiously, I made a Class with the same interface like base Exception Class but not extending/ derived from it. Just old plain PHP object to act like an exception. I knew this would not work as explained here but tried anyway since after all exceptions are just like normal classes.
class MyException {
/**
* properties omitted
*/
public function __construct( string $message = "",int $code)
public function getMessage(void)
//more methods
}
// somewhere in code block
throw new MyException("Fatal error");
// Fatal error: exceptions must be valid objects derived from exception base class.
Can you please explain other ways exceptions are different from regular classes and how they achieve their roles of being exceptional in our code. I know this might be stupid question, but I was just hoping to understand more about how exceptions really work.