Some More Methods to Handle Exceptions
Learn about the different methods of exception handling and when not to handle exceptions.
Additional exception handling methods
The Exception
class is a PHP built-in class that provides several helpful methods. Though we’ve just used getMessage()
so far, there are a lot of other methods as well. The following two are particularly useful:
getFile()
returns the path to the file in which the error occurred.getLine()
returns the line in which the exception occurred.
We can now use the getFile()
and getLine()
methods to add the path and line in which the exception has occurred to the custom message.
Get hands-on with 1400+ tech skills courses.