1 /* GNU Mailutils -- a suite of utilities for electronic mail
2    Copyright (C) 2004-2021 Free Software Foundation, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 3 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General
15    Public License along with this library.  If not, see
16    <http://www.gnu.org/licenses/>. */
17 
18 #ifndef _MUCPP_ERROR_H
19 #define _MUCPP_ERROR_H
20 
21 #include <string>
22 #include <mailutils/errno.h>
23 #include <mailutils/error.h>
24 
25 namespace mailutils
26 {
27 
28 class Exception
29 {
30  protected:
31   int pstatus;
32   const char* pmethod;
33   const char* pmsgerr;
34 
35  public:
Exception(const char * method_name,int status)36   Exception (const char* method_name, int status) {
37     pstatus = status;
38     pmethod = method_name;
39     pmsgerr = mu_strerror (status);
40   }
41 
Exception(const std::string method_name,int status)42   Exception (const std::string method_name, int status) {
43     pstatus = status;
44     pmethod = method_name.c_str ();
45     pmsgerr = mu_strerror (status);
46   }
47 
status()48   int status () const {
49     return pstatus;
50   }
51 
method()52   const char* method () const {
53     return pmethod;
54   }
55 
msg_error()56   const char* msg_error () const {
57     return pmsgerr;
58   }
59 
what()60   const char* what () const {
61     return pmsgerr;
62   }
63 };
64 
65 inline int
verror(const char * fmt,va_list ap)66 verror (const char* fmt, va_list ap)
67 {
68   return mu_verror (fmt, ap);
69 }
70 
71 inline int
error(const char * fmt,...)72 error (const char* fmt, ...)
73 {
74   va_list ap;
75   va_start (ap, fmt);
76   mu_verror (fmt, ap);
77   va_end (ap);
78   return 0;
79 }
80 
81 }
82 
83 #endif /* not _MUCPP_ERROR_H */
84 
85