| Quentin (47) | |||
|
Hi there, I have to write a template class which will be imitating an ordinary variable such as int. It has to be based on dynamic allocation. Following is an example:
It should include handy and useful overloaded operators and functions. Besides, I have to implement proper exception handling (according to my prerequisites, the following throws are incorrect: throw 7 or throw "Error in module foo). So here are my questions: 1) What is proper exception handling? I should derive my own exception class from the standard one named exception? 2) Where are potentially dangerous places in such class to throw an exception? 3) What useful overloaded operators along with operator+ or operator- should I embed into my class? Regards. | |||
|
Last edited on
|
|||
| JLBorges (1756) | |||||
|
> What is proper exception handling? I should derive my own exception class from the standard one named Not necessarily. You could throw std::overflow_error or std::invalid_argument. And ideally catch them by reference to const.
> Where are potentially dangerous places in such class to throw an exception? In the normal case, in destructors, move constructors or move assignment operators. However, if you hold raw resources, everywhere. > What useful overloaded operators along with operator+ or operator- should I embed into my class? Other than conversion operators, only those operators where you want to intercept and check for errors (overflow etc) are required. For example:
| |||||
|
Last edited on
|
|||||