Exercise

Capturing a context stack

Getting the stack context, which is like a stack trace in other languages, is a powerful way to debug complex and nested functions.

In the code below, we want to capture the stack context and record it in the exception handlers of both nested blocks. Then, we want to review its output in the errors table to help debug what's causing the exception in this function.

Instructions

100 XP
  • Declare a text variable, exc_context, to hold the stack context.
  • Store the PG_EXCEPTION_CONTEXT in our exc_context variable in the first handler.
  • Store the PG_EXCEPTION_DETAIL in our exc_detail variable in the second handler.
  • Record both the error message and the stack context in both blocks.