Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

unwindProtect

unwindProtect( 
[ g_protectedForm ] 
[ g_cleanupForm ]
) 
=> g_result

Description

Evaluates the g_protectedForm expression and then executes the SKILL g_cleanupForm expression. Even if the evaluation of g_protectedForm is interrupted or encounters an error, the g_cleanupForm expression is still executed. You can therefore use g_cleanupForm to close open file handles, reset variables, and restore the state to a known value.

If an error occurs within g_protectedForm, the program would normally stop after executing g_cleanupForm. To force continued execution despite the error, wrap unwindProtect with a suitable function to catch errors, such as errset. Even if the error is caught using errset, g_cleanupForm will still be executed.

To include more than a single expression, group expressions by using functions such as progn, let, or prog.

Arguments

g_protectedForm

Name of the function to be evaluated.

g_cleanupForm

Any valid SKILL expression.

Value Returned

g_result

Result of the expression evaluated.

Examples

unwindProtect(undefFun() printf("cleanup form called here\n"))

The outputs are as follows:

*Error* eval: undefined function - undefFun
cleanup form called here
unwindProtect(
    {
     printf("first statement\n")
1/0
printf("second statement\n")
}
printf("cleanup form called here\n")
)

The outputs are as follows:

first statement
*Error* quotient: Attempted to divide by zero
cleanup form called here
errset(
    unwindProtect(
     {
printf("first statement\n")
1/0
printf("second statement\n")
}
printf("cleanup form called here\n")
)
)
printf("program continued after error\n")

The outputs are as follows:

first statement
cleanup form called here
program continued after error

Related Topics

Function and Program Structure


Return to top
 ⠀
X