w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Pattern to prevent continually checking error?

If each function call of a function needs error checking then every time you call that function you should check for errors. The reason is even though it is the same function the inputs are different and the global (and static local) variable are different changing the results. What this means is that if you want to check for errors you are not actually wasting the computational work.

Edit: I don't know if this is wise but you can use Macros to clean up the syntax of

err = a(x);
if(err) return err;

It would look something like

#define error_check(f, e) 
e = f; 
if(e) return e;

So in your code you can just write

error_check(a(x),err)

I am not expeirenced with macros but this should work.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.