PHPException getTraceAsString() Method
Example
Output the stack trace:
<?php
function myFunction($num) {
throw new Exception("An error occurred");
}
try {
myFunction(5);
} catch (Exception $e) {
print_r($e->getTraceAsString());
}
?>
Try it Yourself »function myFunction($num) {
throw new Exception("An error occurred");
}
try {
myFunction(5);
} catch (Exception $e) {
print_r($e->getTraceAsString());
}
?>
Definition and Usage
ThegetTraceAsString() method returns a stack trace in the form of a string.
Stack traces contain information about all of the functions that are running at a givenmoment. The stack trace provided by this method has information about the stack at thetime that the exception was thrown.
Syntax
$exception->getTraceAsString()
Technical Details
| Return Value: | Returns a stack trace in the form of a string |
|---|
Related Pages
Read more about Exceptions in ourPHP Exceptions Chapter.
PHP Reference: ThegetTrace() Method.
❮ PHP Exception Reference

