Questions tagged [stack-trace]

A report of the active stack frames at a certain point in time during the execution of a program.

A stack trace is a report of the active stack frames at a certain point in time during the execution of a program and is often referred to as a stack backtrace.

A stack trace is commonly used during interactive and post-mortem debugging. It typically lists all the functions awaiting return values on the stack at the time of the error. By examining what is on the stack and comparing it to what you expect, you can often determine how the error occurred. By inspecting the function containing the error, you may be able to edit and correct the problem.

A stack trace allows to track the sequence of nested functions called up to the point where the stack trace is generated. In a post-mortem scenario this is up to function where the failure occurred (but not necessarily is caused there). Sibling function calls are not visible in a stack trace.

Before you start

Please browse the list of frequently asked questions to see if your question is similar to one that has already been answered.

The tag should be used to mark questions related to generating, interpreting, debugging, or otherwise understanding stack traces.

2320 questions
74
votes
8 answers

How can I get a call stack listing in Perl?

Is there a way I can access (for printout) a list of sub + module to arbitrary depth of sub-calls preceding a current position in a Perl script? I need to make changes to some Perl modules (.pm's). The workflow is initiated from a web-page thru a…
slashmais
  • 7,069
  • 9
  • 54
  • 80
73
votes
15 answers

How to get a stack trace for C++ using gcc with line number information?

We use stack traces in proprietary assert like macro to catch developer mistakes - when error is caught, stack trace is printed. I find gcc's pair backtrace()/backtrace_symbols() methods insufficient: Names are mangled No line information 1st…
dimba
  • 26,717
  • 34
  • 141
  • 196
71
votes
6 answers

How to get a stack trace object in Ruby?

I need to get a stack trace object in Ruby; not to print it, just to get it to do some recording and dumping for later analysis. Is that possible? How?
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
71
votes
5 answers

Exception without stack trace in Java

This is probably a very naive question. I used to believe that a Throwable in Java always contains the stack trace. Is it correct? Now it looks like that I catch exceptions without the stack trace. Does it make sense? Is it possible to catch an…
Michael
  • 41,026
  • 70
  • 193
  • 341
68
votes
4 answers

How to get the Stack trace when logging exceptions with NLog?

When I use the default layout with NLog it only prints the name of the exception. I've been told that the log4jxmlevent layout doesn't prints nothing about the exception. What layout will help me? Example code: try { throw new…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
63
votes
12 answers

Can I get detailed exception stacktrace in PowerShell?

Runing such script: 1: function foo() 2: { 3: bar 4: } 5: 6: function bar() 7: { 8: throw "test" 9: } 10: 11: foo I see test At C:\test.ps1:8 char:10 Can I get a detailed stack trace instead? At bar() in C:\test.ps1:8 At foo() in…
alex2k8
  • 42,496
  • 57
  • 170
  • 221
63
votes
4 answers

Best way to invoke gdb from inside program to print its stacktrace?

Using a function like this: #include #include #include #include void print_trace() { char pid_buf[30]; sprintf(pid_buf, "--pid=%d", getpid()); char name_buf[512]; …
Vi.
  • 37,014
  • 18
  • 93
  • 148
62
votes
14 answers

How do I log a stacktrace using java's Logger class

I am using Java's Logger class. I want to pass ex.printStackTrace() into Logger.log(loglevel, String), but printStackTrace() returns void. So I am not able to pass and print the stack trace of the exception. Is there any way that I can convert void…
Surya Joseph
  • 661
  • 1
  • 5
  • 5
60
votes
1 answer

Stack traces with async/await

It's clear why stack traces are affected with Microsoft's new programming paradigm. We now have a semantic stack and a couple of physical ones (my choice of words). What I get to see is an exception's StackTrace property (and in the debugger) is the…
John
  • 6,693
  • 3
  • 51
  • 90
60
votes
3 answers

NullPointerException stack trace not available without debug agent

I have recently found a bug that causes a NullPointerException. The exception is caught and logged using a standard slf4j statement. Abridged code below: for(Action action : actions.getActions()) { try { context =…
omerkudat
  • 9,371
  • 4
  • 33
  • 42
57
votes
2 answers

Re-raise Python exception and preserve stack trace

I'm trying to catch an exception in a thread and re-raise it in the main thread: import threading import sys class FailingThread(threading.Thread): def run(self): try: raise ValueError('x') except ValueError: …
roskakori
  • 3,139
  • 1
  • 30
  • 29
57
votes
6 answers

(Unknown Source) in Exception stack trace

Background This question is related to Why does String.valueOf(null) throw a NullPointerException? Consider the following snippet: public class StringValueOfNull { public static void main(String[] args) { String.valueOf(null); …
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
55
votes
5 answers

e.printStackTrace(); in string

There are e.printStackTrace() method to print exceptional error, so I would like to take entire exception in String and show it by Toast.makeText() How can i do this? If there are more alternate idea, then please share with me or suggest me.
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133
55
votes
4 answers

Determining Current Call Stack (For Diagnostic Purposes)

For diagnostic purposes I sometimes need to store the call stack that lead to a given state transition (such as granting a lock, committing a transaction, etc.) so that when something goes wrong later I can find out who originally triggered the…
Thilo-Alexander Ginkel
  • 6,898
  • 10
  • 45
  • 58
55
votes
12 answers

How can I get PHP to produce a backtrace upon errors?

Trying to debug PHP using its default current-line-only error messages is horrible. How can I get PHP to produce a backtrace (stack trace) when errors are produced?
chaos
  • 122,029
  • 33
  • 303
  • 309