Page 279 of 346 Start Back Next End ZBasic System Library 267 ZBasic Microcontrollers SetJmp Type Function returning Integer Invocation SetJmp(jmpbuf) Parameter Method Type Description jmpbuf ByRef array of Byte A buffer to hold the return context, see description below. Discussion This function, in conjunction with LongJmp(), provides a way to circumvent the normal call-return structure and return directly to a distant caller. It is the equivalent of a non-local Goto function and can be used, among other things, to handle exceptions in your programs. The parameter specifies a Byte array that will be initialized with context information to allow a direct return from deeply nested calls. The array must be a minimum size (either 6 bytes or 24 bytes for VM mode and native mode, respectively) to hold the context information for unwinding the call stack. You can use the built-in constant System.JumpBufSize to ensure that it is the proper size. On the initial call to SetJmp() the return value will always be zero. When control is returned via a call to LongJmp(), the return value will be the value supplied as the second parameter to the LongJmp() call. Generally, you should choose this value to indicate the nature of the exception condition and in most cases it should be non-zero. The jump buffer needs to be accessible to the LongJmp() caller. Often, this is realized by making it a global or module-level variable. If you want it to be a local variable, you’ll have to pass the buffer as a parameter down the call chain. See the section on Exception Handling in the ZBasic Reference Manual for more details. Caution If the provided array is less than minimum required size, adjacent memory locations will be modified usually with undesirable results. Your application should not directly modify the contents of the array. Doing so may cause unpredictable behavior. Compatibility This routine is not available in BasicX compatibility mode. See Also LongJmp