public virtual member function
<exception>
std::exception::~exceptionvirtual ~exception throw();
Destroy exception
Destroys the exception object.As a virtual function, derived classes may redefine its behavior.
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
// exception virtual destructor
#include <iostream> // std::cout
#include <exception> // std::exception
#include <cstring> // std::strlen, std::strcpy
// text_exception uses a dynamically-allocated internal c-string for what():
class text_exception : public std::exception {
char* text_;
public:
text_exception(const char* text) {
text_ = new char[std::strlen(text)+1]; std::strcpy (text_,text);
}
text_exception(const text_exception& e) {
text_ = new char[std::strlen(e.text_)+1]; std::strcpy (text_,e.text_);
}
~text_exception() throw() {
delete[] text_;
}
const char* what() const noexcept {return text_;}
};
int main () {
try {
throw text_exception("custom text");
} catch (std::exception& ex) {
std::cout << ex.what();
}
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4