Professional Documents
Culture Documents
2 - Exception Handling in Depth
2 - Exception Handling in Depth
Monica Ciocan
May 14, 2012
Summary
Robustness:
● helps to easily trace the error
● terminate the program if it cannot handle the
problem
private:
T* v_; //ptr to a memory area big
size_t vsize_; // enough for 'vsize_' T's
size_t vused_; // nr of T's actually in use
};
Ensure that the errors always leave your program in a valid
state(basic guarantee).
Remember: error unsafe and „poor design“ go hand in hand.
Prefer cohesion – always eandeavor to give each piece of
code a single well defined responsability.
Avoid exception specifications.
In each function, take all the code that might emit an error and
do all that work safetly off to the side. Only when this work
succeeded, should you modify the program state using only
non-throwing operations.
May 14, 2012 Exception Handling in Depth 23
Summary