Use C++ Exception; Moved calculation code to a function; ...