Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

getTrace()

Example

Display the stack trace.

<?php
function myFunction($num) {
  throw new Exception(“An error occurred”);
}

try {
  myFunction(5);
catch (Exception $e) {
  print_r($e->getTrace());
}
?>

Definition and Usage

The getTrace() method returns a stack trace as an array.

 

Stack traces include information about all the functions executing at a specific moment. The stack trace returned by this method provides details about the stack at the time the exception was thrown.

Syntax

$exception->getTrace()

Technical Details

Return Value:

Returns a stack trace as an array.