You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on "Clean Code" book, I find this section very useful. Use exceptions to indicate on error occurred instead of returning error codes, it complicates the caller function's code.
// bad
int func1(){
if (some condition)
return -1; // Error
return 0; // Ok
}
void func2(){
if (func1() == 0)
return;
}
// good
void func1(){
if (some condition)
throw new Exception(); // Error
return; // Ok
}
void func2(){
try
{
func1();
} catch (Exception ex) {
// Error
}
}
The text was updated successfully, but these errors were encountered:
Based on "Clean Code" book, I find this section very useful. Use exceptions to indicate on error occurred instead of returning error codes, it complicates the caller function's code.
// bad
// good
The text was updated successfully, but these errors were encountered: