ITPEC FE Morning October 2022 Question 48
Which of the following is the most appropriate description of a stack trace that is used for debugging a program?
Explanation
A trace of the call stack of methods, functions and subroutines — it lists the chain of calls that were active when an error occurred.
Each time a function is called, a frame with its return address and local data is pushed onto the call stack, and it is popped when the function returns. When an exception or crash happens, the stack trace prints these frames, innermost first, usually with file names and line numbers. Reading it tells the programmer where the failure happened and through which sequence of calls the program got there.
Answer (a)
Why not others:
- •(b) — a stack trace belongs to the program that failed; it does not collect traces left by other programs
- •(c) — it is a live report of the call stack at the moment of the error, not leftovers in memory from a stack data structure
- •(d) — it follows the runtime call stack whether or not the program itself uses a stack data structure; "stack" here means the call stack
Key rule: Read a stack trace from the top frame, where the error was raised, down through its callers to find the first frame in your own code, which is usually where the bug is.
System Development Technology · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.