![]() |
help createing exception class from base STL exception
For my c++ course work, i need to complete a partially written c++ porgram.
this program throws an exception class called "interpreter_exception". i need to write this exception class. ive noticed that in the catch blocks, this exception is treated very similar, if not exactly the same as the STL exception class, so im thinking it would be a good idea to make interpreter_exception a derived class, from super class stl::exception. what do i need to do in order to make this work ? are there any virtual / pure virtual functions i will ned to define ? or will a simple Code:
class interpreter_exception : public stl::exception {};thanks. |
Standard way:
Code:
class interpreter_exception : public std::exception |
Ahh perfect, thanks alot.
|
OOPS !
correction.... its the std::runtime_error that i should inheit from, not std::exception. but i think the code you gave me is the same, except i need to use a iffernent library < stdexcept > instad of < exception > edit: oops, nope. my following class generate the errors shown... Code:
#ifndef CXS12U_EXCEPTIONS_HPPCode:
bash-2.05b$ g++ src/main.cpp -o bin/jminusIf i could find decent documentation on etd::exception class, i could do all this myself. my c++ book is quite old, and only goes as far as throwing intergers floats, bools and char's for exceptions ! |
std::runtime_error is a subclass of std::exception. If you inherit from std::runtime_error instead, the code can be simplified somewhat:
Code:
class interpreter_exception : public std::runtime_error |
| All times are GMT -5. The time now is 08:36 PM. |