fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class SomeClass
  7. {
  8. public:
  9. void make_exception(const string &msg)
  10. {
  11. err = "Error: ";
  12. err += msg;
  13. throw err.c_str();
  14. };
  15. private:
  16. string err;
  17. };
  18.  
  19.  
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23. SomeClass obj;
  24.  
  25. try {
  26. obj.make_exception("Test");
  27. } catch (const char *e) {
  28. cout << "Exception thrown with message: \"" << e << '"';
  29. }
  30. }
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
Exception thrown with message: "Error: Test"