try { // some code that throws an exception } catch (Exception $e) { $severity = $e->getSeverity(); switch($severity) { case E_ERROR: echo "Fatal error occurred"; break; case E_WARNING: echo "Warning occurred"; break; case E_NOTICE: echo "Notice occurred"; break; // and so on for other severity levels } }In this example, the code is executed inside a try-catch block, and when an exception is caught, the severity of the exception is retrieved using the getSeverity method. Depending on the severity level, a different message is displayed. This method is part of the PHP core library.