fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3.  
  4. class C {
  5. public:
  6. C(const size_t aa, const size_t bb) : a(aa), b(bb) {
  7. if (aa == 0)
  8. throw std::runtime_error("aa must be > 0");
  9. if (bb == 0)
  10. throw std::runtime_error("bb must be > 0");
  11. if ((aa + bb) > 10) {
  12. throw std::runtime_error("aa + bb must be <= 10");
  13. }
  14. }
  15. private:
  16. size_t a;
  17. size_t b;
  18. };
  19.  
  20. int main() {
  21. C c1(1, 2); // OK
  22. C c2(5, 6); // error
  23. return 0;
  24. }
Runtime error #stdin #stdout #stderr 0s 4304KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::runtime_error'
  what():  aa + bb must be <= 10