N
Nick Keighley
Hi,
Perhaps I was little ambitious with this template class.
When I define exception classes for packages I seemed to write code
similar to this each time:-
class DecompressionError : public std::runtime_error
{
public:
DecompressionError (const std::string& what = "")
: runtime_error(std::string("Decompression Error ") + what)
{
}
virtual ~DecompressionError()
{
}
};
Any comments on the wisdom of such a class?
This looked like a good use for templates. Hence:-
#include <string>
#include <stdexcept>
template class<const char* NAME> class Error: public std::runtime_error
// line 19
{
public:
Error (const std::string& what = "")
: runtime_error(std::string(NAME) + " Error ") + what)
{
}
virtual ~Error()
{
}
};
int main (void)
{
Error ("Pippo") pippo_x;
try
{
throw Error("Pippo");
}
catch (Error ("Pippo")& e)
{
cerr << e.what();
}
}
This actually crashed the compiler!
:\bin\error_templ.cpp(19) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1188)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more
information
So does my code look ok?
--
Nick Keighley
Programming should never be boring, because anything
mundane and repetitive should be done by the computer.
~Alan Turing
Perhaps I was little ambitious with this template class.
When I define exception classes for packages I seemed to write code
similar to this each time:-
class DecompressionError : public std::runtime_error
{
public:
DecompressionError (const std::string& what = "")
: runtime_error(std::string("Decompression Error ") + what)
{
}
virtual ~DecompressionError()
{
}
};
Any comments on the wisdom of such a class?
This looked like a good use for templates. Hence:-
#include <string>
#include <stdexcept>
template class<const char* NAME> class Error: public std::runtime_error
// line 19
{
public:
Error (const std::string& what = "")
: runtime_error(std::string(NAME) + " Error ") + what)
{
}
virtual ~Error()
{
}
};
int main (void)
{
Error ("Pippo") pippo_x;
try
{
throw Error("Pippo");
}
catch (Error ("Pippo")& e)
{
cerr << e.what();
}
}
This actually crashed the compiler!
:\bin\error_templ.cpp(19) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1188)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more
information
So does my code look ok?
--
Nick Keighley
Programming should never be boring, because anything
mundane and repetitive should be done by the computer.
~Alan Turing