How to create a custom C++ exception
Create a header file with the same name as your exception like so:
gcryptinitexception.h
#ifndef GCRYPTINITEXCEPTION_H
#define GCRYPTINITEXCEPTION_H
class GcryptInitException: public std::exception {
public:
GcryptInitException() {}
virtual const char* what() const throw() {
return "Couldn't initialize gcrypt.";
}
};
#endif // GCRYPTINITEXCEPTION_H
Then #include
your header file and throw it like this:throw GcryptInitException();
(Don’t forget the parenthesis at the end)
C++
blog content post