The “fatal error” part is generated because the exception is thrown outside a try-catch statement, and is finally caught by the php error handler. Uncaught exceptions are always fatal.
Try surrounding the code that generates the exception with a try-catch statement like:
try{
$foo->bar();
catch(UserException $ex){
// Do something with the exception.
}
Alternately you could make your own error handler –> Linky.
But the try-catch approach is the “correct” way to do it.
solved PHP exception custom message