language: C++ 4.7.2 (gcc-4.7.2)
date: 307 days 21 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
 
using namespace std;
 
class SomeClass
{
public:
        void make_exception(const string &msg)
        {
            err = "Error: ";
            err += msg;
            throw err.c_str();
        };      
private:
        string err;
};
 
 
 
int main(int argc, char *argv[])
{
        SomeClass obj;
        
        try {
                obj.make_exception("Test");
        } catch (const char *e) {
                cout << "Exception thrown with message: \"" << e << '"';
        }
}
http://stackoverflow.com/a/11481006/629493