PHP Exception Methods

About This Index
This page is the PHP Exception Methods index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn how to throw, catch, chain, and inspect Exception objects on /php/exception. Use this page when you need a specific method such as getMessage(), getPrevious(), or getTraceAsString().
Start with __construct() and getMessage()—then learn getPrevious() and getTraceAsString() for chaining and logs.
How to Call an Exception Method
Exception helpers are object methods—call them on a caught Exception instance:
try {
throw new Exception("Not found", 404);
} catch (Exception $e) {
echo $e->getMessage();
echo $e->getCode();
echo $e->getTraceAsString();
} PHP Exception Methods Table
All method guides in this PHP tutorial series (10 tutorials in 4 categories).
Create
1 methodBuild an Exception with a message, code, and optional previous cause.
| Method | Description | Tutorial |
|---|---|---|
__construct() | Construct the exception with message, code, and previous. | Try it |
Inspect basics
4 methodsRead the message, code, file, and line after you catch an exception.
Chain & trace
4 methodsFollow nested causes and inspect the call stack.
| Method | Description | Tutorial |
|---|---|---|
getPrevious() | Return the previous Throwable, or null. | Try it |
getTrace() | Get the stack trace as an array. | Try it |
getTraceAsString() | Get the stack trace as a string. | Try it |
__toString() | Return the string representation of the exception. | Try it |
Special
1 methodUnderstand the private final method that blocks cloning.
Frequently Asked Questions
Start with __construct()
Open the first guide—syntax, examples, and FAQs.
6 people found this page helpful
