R
Ralph A. Moeritz
Hello,
I'd like to implement an exception handling mechanism
in my C programs. Up to now I have been using a local
error handling scheme where errors are handled (when
appropriate) in the lowest-level functions eg.
char *
foo (void)
{
int err = 0; /* (error flag: 1=set) */
char *str = xmalloc (BUF_LEN);
int ret = do_something (str);
if (!ret)
{
++err;
goto clean_up;
}
clean_up:
if (err)
{
/* handle error */
}
return str;
}
void
bar (void)
{
char *s = foo ();
/* ... */
}
What this sheme lacks is a way for the called function to pass error
information back to the calling function so that it can deal with it
in appropriate situations. I've heard of people implementing TRY,
CATCH, THROW using setjmp & longjmp, but I've never seen any code
for this...
Regards,
Ralph
I'd like to implement an exception handling mechanism
in my C programs. Up to now I have been using a local
error handling scheme where errors are handled (when
appropriate) in the lowest-level functions eg.
char *
foo (void)
{
int err = 0; /* (error flag: 1=set) */
char *str = xmalloc (BUF_LEN);
int ret = do_something (str);
if (!ret)
{
++err;
goto clean_up;
}
clean_up:
if (err)
{
/* handle error */
}
return str;
}
void
bar (void)
{
char *s = foo ();
/* ... */
}
What this sheme lacks is a way for the called function to pass error
information back to the calling function so that it can deal with it
in appropriate situations. I've heard of people implementing TRY,
CATCH, THROW using setjmp & longjmp, but I've never seen any code
for this...
Regards,
Ralph