📄 exception.h
字号:
/************************************************************************* * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * *************************************************************************/#ifndef _EXCEPTION_H__#define _EXCEPTION_H__#include "global.h"#include <exception>#include <string>#include <stdio.h>using namespace std;/** * This is the base class for all exceptions that will be thrown by * libsmtp++. * All child classes should set this->name to the name of the exception * in the constructor. */class Exception : public exception{ public: /** * Constructor. * * @param msg The error msg. * @param method The method from where this exception was thrown. * @param index An integer that uniquely identifies this exception inside * the method it was thrown from. */ inline Exception (const string &msg, const string &method, unsigned int index) { this->msg = msg; this->method = method; this->index = index; }; /** * Destructor. */ virtual ~Exception () throw () {}; /** * Returns an informal message about the reason why this exception * was thrown. * * @returns The reason why this exception was thrown. */ const char * what () { char buf[1024]; sprintf (buf,"%03d", this->index); string msg = this->name + "(" + this->method + " - " + buf + "): " + this->msg; return (msg.c_str ()); }; /** * Returns the method where this exception was thrown from. * * @returns The method where this exception was thrown from. */ const char * get_method () { return (this->method.c_str ()); }; /** * Returns the index of this exception that uniquely identifies it inside * the method it was thrown from. * * @returns The index of theis exception. */ unsigned int get_index () { return (this->index); }; /** * Returns an informal error message. * * @returns The error message. */ const char * get_msg () { return (this->msg.c_str ()); }; /** * Returns the name of this exception. * * @returns The name of this exception. */ const char * get_name () { return (this->name.c_str ()); }; protected: /** * The error message. */ string msg; /** * The method this exception was thrown from. */ string method; /** * An integer that uniquely identifies this exception inside * the method it was thrown from. */ unsigned int index; /** * The name of this exception. */ string name;};/** * Will be thrown on ssl related problems. */class SSLException : public Exception{ public: inline SSLException ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "SSLException"; }; virtual ~SSLException () throw () {};};/** * Will be thrown on SHA1 checksumming related problems. */class SHA1Exception : public Exception{ public: inline SHA1Exception ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "SHA1Exception"; }; virtual ~SHA1Exception () throw () {};};/** * Will be thrown if the selected authentication mechanism * is not available from the SMTP server. */class UnsupportedAuthenticationMechanismException : public Exception{ public: inline UnsupportedAuthenticationMechanismException ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "UnsupportedAuthenticationMechanismException"; }; virtual ~UnsupportedAuthenticationMechanismException () throw () {};};/** * Will be thrown on IO related problems. */class IOException : public Exception{ public: inline IOException ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "IOException"; }; virtual ~IOException () throw () {};};/** * Will be thrown on BASE64 decoding problems. */class DecodeException : public Exception{ public: inline DecodeException ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "DecodeException"; }; virtual ~DecodeException () throw () {};};/** * Will be thrown on authentication problems. */class AuthenticationFailedException : public Exception{ public: inline AuthenticationFailedException ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "AuthenticationFailedException"; }; virtual ~AuthenticationFailedException () throw () {};};/** * Will be thrown on transfer related problems. */class TransferException : public Exception{ public: inline TransferException ( const string &msg, const string &method, unsigned int index ) : Exception (msg, method, index) { this->name = "TransferException"; }; virtual ~TransferException () throw () {};};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -