win12.hlp (Table of Contents; Topic list)
WinThrow (1.2)
                                                      Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_WINCATCHTHROW
 
VOID WinThrow(pctchbf, sErrorReturn)
PCATCHBUF pctchbf;     /* address of structure with execution environment */
SHORT sErrorReturn;    /* error code to return                            */
 
The WinThrow function restores the execution environment to the values saved
in the buffer pointed to by the pctchbf parameter. Execution then transfers
to the WinCatch function that copied the environment to pctchbf.
 
Parameter     Description
────────────────────────────────────────────────────────────────────────────
 
pctchbf       Points to a CATCHBUF structure that contains the execution
              environment. It must have been set by a previous WinCatch
              function call.
 
sErrorReturn  Specifies the value to be returned to the WinCatch function.
              The meaning of the value is determined by the application.
 
Return Value
 
This function does not return a value.
 
Comments
 
The routine that calls WinCatch is responsible for freeing any resources
allocated between the time WinCatch was called and the time WinThrow was
called.
 
Example
 
This example calls WinCatch to save the current execution environment before
calling a recursive sort function. The first return from WinCatch is zero.
If the doSort function calls WinThrow, execution will again return to the
WinCatch function. This time, WinCatch will return the STACKOVERFLOW error
passed by the doSort function. The doSort function is recursive, that is, it
calls itself. It maintains a variable, usStackCheck, that is used to check
to see how much stack space has been used. If more then 3K of the stack has
been used, it calls WinThrow to drop out of all the nested function calls
back into the function that called WinCatch.
 
USHORT usStackCheck
CATCHBUF ctchbf;
 
main() {
    SHORT sErrorReturn;
 
    sErrorReturn = WinCatch(&ctchbf); /* save execution environment */
    if (sErrorReturn) {
        .
        . /* error processing */
        .
    }
    usStackCheck = 0;               /* initialize stack usage count */
    doSort(1, 1000);                /* call sort function           */
}
 
VOID doSort(sLeft, sRight)
SHORT sLeft, sRight;
{
    SHORT i, sLast;
 
    /*
     * check to see if more then 3K of the stack has been used, and if
     * so, call WinThrow to drop back into the original calling program
     */
 
    usStackCheck += 10;
    if (usStackCheck > (3 * 1024))
        WinThrow(&ctchbf, STACKOVERFLOW);
    .
    . /* sorting algorithm */
    .
    doSort(sLeft, sLast - 1);         /* note recursive call         */
    usStackCheck -= 10;               /* update stack check variable */
}
 
See Also
 
WinCatch, CATCHBUF