C
Christopher Benson-Manica
Can you goto switch labels?
int i=0; /* arbitrary */
switch( i ) {
case 0:
if( !some_validity_check() ) {
goto error; /* could be default as well */
}
/* proceed normally */
break;
case 1:
if( !some_other_validity_check() ) {
goto error;
}
/* proceed normally */
break;
case 2:
if( !yet_another_validity_check() ) {
goto error;
}
/* proceed normally */
break;
error:
default: /* invalid input */
handle_error();
exit( EXIT_FAILURE ); /* or something */
}
/* proceed normally */
If this is possible, is it a reasonable choice stylistically, to avoid
re-coding the error handling code?
int i=0; /* arbitrary */
switch( i ) {
case 0:
if( !some_validity_check() ) {
goto error; /* could be default as well */
}
/* proceed normally */
break;
case 1:
if( !some_other_validity_check() ) {
goto error;
}
/* proceed normally */
break;
case 2:
if( !yet_another_validity_check() ) {
goto error;
}
/* proceed normally */
break;
error:
default: /* invalid input */
handle_error();
exit( EXIT_FAILURE ); /* or something */
}
/* proceed normally */
If this is possible, is it a reasonable choice stylistically, to avoid
re-coding the error handling code?