Hello all.
I'm not very familiar with machine code, but I think this is a pretty simple question.
If I want to do error handling via an integer returned from a function (as opposed to the function throwing an exception), is it better practice—from a machine code standpoint—to:
- Check the integer in a conditional statement for a "bad" value, and then use a switch statement to handle the "bad" value(s), or
- Switch the integer, and provide a case for the "good" value(s) as well as the "bad" value(s)
For example, in C++:
enum error_code {E_GOOD, E_BAD, E_UGLY};
error_code func_b();
Option 1
void func_a()
{
error_code err_catch = func_b();
if (err_catch)
{
switch (err_catch)
{
case E_BAD:
/* Handle bad case */
break;
case E_UGLY:
/* Handle ugly case */
break;
}
}
}
Option 2
void func_a()
{
error_code err_catch = func_b();
switch (err_catch)
{
case E_GOOD:
break;
case E_BAD:
/* Handle bad case */
break;
case E_UGLY:
/* Handle ugly case */
break;
}
}
Thank you for your help.