Function ProcName() Foundation

Retrieves a procedure or function name from the call stack.

Syntax
ProcName( [<nCallStack>], [<nThreadId>] ) --> cFunctionName
Parameters
<nCallStack>
<nCallStack> is a positive integer indicating the position within the call stack of the function or procedure whose name is returned. The default value is zero and designates the current function or procedure.
<nThreadId>
<nThreadId> is a positive numeric identifying the thread whose current function/procedure name is returned. The default value is the return value of ThreadId().
Return

The return value of ProcName() is a character string containing the name of a called function or procedure from the call stack.

Description

The debug function ProcName() provides the name of a procedure or function from the call stack. The call stack contains an entry for each function, procedure, method or code block while the corresponding program code is being processed. When a code block is executed, ProcName() provides the name of the function in which the code block was defined with a prefixed "(B)".

The function ProcName() is used along with the function ProcLine() to determine the location of an error.

Examples
ProcName()
// In the example, the return values of ProcName() are 
// demonstrated. 

PROCEDURE Main 
   LOCAL  cName := ProcName() 
   ? cName                    // result: MAIN 
   UserFunc() 

RETURN 

FUNCTION UserFunc() 

   ? ProcName()               // result: USERFUNC 
   ? ProcName(1)              // result: MAIN 
   ? ProcName(2)              // result:    (null string ("")) 

RETURN NIL 
Write the call stack to a file

// The example shows a function which writes the call stack 
// to a file. This information is very useful in tracking down 
// errors if a "fatal error" occurs. See the function 
// ErrorBlock() for an example of an extensive error log 
// which encompasses more than just the call stack. 

FUNCTION WriteCallStack( cFileName ) 
   LOCAL n := 0 

   SET CONSOLE OFF 
   SET PRINTER TO (cFileName) 
   SET PRINTER ON 

   DO WHILE ! Empty( ProcName(++n) ) 
      ? ProcName(n)             + "(" + ; 
        LTrim(Str(ProcLine(n))) + ")" 
   ENDDO 

   SET CONSOLE ON 
   SET PRINTER TO 
   SET PRINTER OFF 
RETURN NIL 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.