This is quite a bit of code-duplication, create a helper function like "checkError()" or "printResult", that takes the error-code as input, and handles this bit, instead of typing out the if in every function.