fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3. #include <limits>
  4.  
  5. using namespace std;
  6.  
  7. double _div(double a, double b) throw(underflow_error)
  8. {
  9. double result = a / b;
  10. if ( a && result < numeric_limits<double>::min() )
  11. throw underflow_error("underflow!");
  12. return result;
  13. }
  14.  
  15. int main()
  16. {
  17. try {
  18. double x = _div(numeric_limits<double>::min(), numeric_limits<double>::max());
  19. cout << x << endl;
  20. } catch (const exception &e) {
  21. cout << e.what() << endl;
  22. }
  23. try {
  24. double x = _div(0, 5);
  25. cout << x << endl;
  26. } catch (const exception &e) {
  27. cout << e.what() << endl;
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
underflow!
0