Programming Guide



sm_menu_bar_error

Returns the last error returned by a menu function

int sm_menu_bar_error(void);

Returns

Description

sm_menu_bar_error returns the error generated by the last call to a menu function. This is particularly useful for calls to sm_menu_get and sm_mnitem_get and their variants. These functions return the value of the specified property when successful; otherwise, they return -1 for failure of the _get_int variants, and 0 for the _get_str variants. sm_menu_bar_error returns the actual cause of failure. It also lets you determine whether a return of -1 indicates the property's actual value or an error condition.

Because Panther retains the error code only for the last call to one of the menu functions, call sm_menu_bar_error immediately afterward to evaluate the call's return status.

Example

/*enable and disable menu tear-offs*/

int ToggleTearOffs(void)
{
int errorCode;
switch(sm_menu_get_int(MNL_SCREEN, "menucom", "main", MN_TEAR))
{
case 0: /*enable tear-offs */
sm_menu_change
(MNL_SCREEN, "menucom", "main", MN_TEAR, 1, NULL);
break;

case 1: /*disable tear-offs */
sm_menu_change
(MNL_SCREEN, "menucom", "main", MN_TEAR, 0, NULL);
break;

case -1: /* if error returned, find out why */
errorCode = sm_menu_bar_error();
menuErrorHandler(errorCode);
break;
}
}