// // main.cpp // Exceptions // // Created by Robert Metcalfe on 18/09/13. // Copyright (c) 2013 Robert Metcalfe. All rights reserved. // #include #include class OutOfRange { public: OutOfRange(double d) { std::cout << "Out of range " << d << std::endl; } }; double mycuberoot(double ind) { if (ind < 0) { throw new OutOfRange(ind); } else { try { if (isinf(pow(ind, (1.0 / 3.0)))) std::cout << "Is Infinity "; if (isnan(pow(ind, (1.0 / 3.0)))) std::cout << "Is Not-A-Number " << ind << " "; return pow(ind, (1.0 / 3.0)); } catch (const std::string& ex) { std::cout << ex << std::endl; } catch (const std::exception& ex) { std::cout << ex.what() << std::endl; } catch (...) { std::cout << "Error" << std::endl; } } } int main(int argc, const char * argv[]) { try { std::cout << mycuberoot(1.0E1999876) << std::endl; std::cout << mycuberoot(95.0) << std::endl; std::cout << mycuberoot(-95.0) << std::endl; } catch (...) { } return 0; }