Tag Info

New answers tagged

0

Its a reasonably common practice - C programs (and other systems, eg errno) often to store the last error in a location so you can pick the details out if a function returned an error code. There's no reason why you can't do the same. However, if you do this you have to take a few things into consideration. Threads are very important, each error info must ...


0

You can factor out the error handling, so that your function can simply return on error. In C/C++ this would look something like this: int handleError(int errorCode, char* message) { if(errorCode) { //Notify user, whatever } return errorCode; } int functionThatCanFail(...) { int result; if(result = handleError(do_stuff(), ...


4

the easiest way to refactor that is to use a success variable, eg res = do_stuff(); if (res) res = do_more_stuff(); if (res) .... If you use a counter instead of a boolean success variable, then you can also tell if all of the steps succeeded at the end (ie. the counter will equal the number of steps that successfully ran) The one thing you ...



Top 50 recent answers are included