EDDYMENS

Published 7 months ago

What Is A Stack Trace?

A stack trace or backtrace, is a report unfolding the execution path of a program.

It's a critical tool used for debugging [→] by following the sequence of execution leading to a specific point, which could be when a program crashes.

Stack traces typically show the names of functions or methods, their associated memory addresses or line numbers in the source code, and sometimes additional contextual information like parameters or local variables.

Stack traces are also good in general for developers looking to understand how a program works.

Here is an example of a stack trace in PHP Laravel, after an exception is thrown:

01: [2023-12-02 15:00:44] local.ERROR: The "-t" option does not exist. {"exception":"[object] (Symfony\\Component\\Console\\Exception\\RuntimeException(code: 0): The \"-t\" option does not exist. at /Users/project-folder/app/vendor/symfony/console/Input/ArgvInput.php:125) 02: [stacktrace] 03: #0 /Users/project-folder/app/vendor/symfony/console/Input/ArgvInput.php(107): Symfony\\Component\\Console\\Input\\ArgvInput->parseShortOptionSet('tag=coding-term...') 04: #1 /Users/project-folder/app/vendor/symfony/console/Input/ArgvInput.php(87): Symfony\\Component\\Console\\Input\\ArgvInput->parseShortOption('-tag=coding-ter...') 05: #2 /Users/project-folder/app/vendor/symfony/console/Input/ArgvInput.php(74): Symfony\\Component\\Console\\Input\\ArgvInput->parseToken('-tag=coding-ter...', true) 06: #3 /Users/project-folder/app/vendor/symfony/console/Input/Input.php(55): Symfony\\Component\\Console\\Input\\ArgvInput->parse() 07: #4 /Users/project-folder/app/vendor/symfony/console/Command/Command.php(285): Symfony\\Component\\Console\\Input\\Input->bind(Object(Symfony\\Component\\Console\\Input\\InputDefinition)) 08: #5 /Users/project-folder/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle)) 09: #6 /Users/project-folder/app/vendor/symfony/console/Application.php(1081): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) 10: #7 /Users/project-folder/app/vendor/symfony/console/Application.php(320): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\contentNew), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) 11: #8 /Users/project-folder/app/vendor/symfony/console/Application.php(174): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) 12: #9 /Users/project-folder/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) 13: #10 /Users/project-folder/app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) 14: #11 {main} 15: "}

Here is another article you might like 😊 What Is A String In Programming