Safer C++ By Handling Function Result
- POST
Overview Despite best efforts to train, educate, warn developers to always capture and handle function results, one still can manage to forget and get burned in the process. Let’s say you have this piece of code that deals with critical process:
int critical_func() { return 1234; } It’s far too common for folks to use critical_func() in this manner:
int use_critical_func() { critical_func(); return 0; } The values returned from critical_func() could mean anything: Cannot connect to a service, balance is empty, rocket is faulty, … Failure to capture and act based on those return values could result in any undefined/undesired behaviour: Memory leak, crash, silent failures, … Let’s see how we can enforce developers to use return value from mission critical functions.