Hi.
I would like to create a custom class exception handler. I want to use it for arbitrary exceptions that are not part of the exception library.
I am having a problem with such a class. Here is the code for that exception class.
-----
#ifndef CEXCEPTIONHANDLE_H
#define CEXCEPTIONHANDLE_H
class ExceptionHandle
{
public:
ExceptionHandle(const char *error) : eMessage(error) {}
const char *what() const throw()
{
return eMessage;
}
private:
const char *eMessage;
};
#endif
-----
I basic want to *throw* a character string to the exception handle. Afterward, have a catch function to call what().
Here is an example of a try/catch.
----
try
{
function(x);
}
catch (ExceptionHandle *e)
{
cerr << e->what();
}
-----
function(int X)
{
if (X == 0)
throw ExceptionHandle("Error: X equals zero.");
}
-----
The program I am working on works, but it crashes whenever "throw ExceptionHandle("Error: X equals zero.");" occurs.
Does anyone know what is wrong with my design and/or implementation?
Thanks,
Kuphryn