| 1 | #ifndef __MDFN_ERROR_H |
| 2 | #define __MDFN_ERROR_H |
| 3 | |
| 4 | #include <errno.h> |
| 5 | #include <string.h> |
| 6 | #include <stdexcept> |
| 7 | |
| 8 | #ifdef __cplusplus |
| 9 | |
| 10 | class ErrnoHolder; |
| 11 | class MDFN_Error : public std::exception |
| 12 | { |
| 13 | public: |
| 14 | |
| 15 | MDFN_Error() throw(); |
| 16 | |
| 17 | MDFN_Error(int errno_code_new, const char *format, ...) throw(); |
| 18 | MDFN_Error(const ErrnoHolder &enh); |
| 19 | |
| 20 | ~MDFN_Error() throw(); |
| 21 | |
| 22 | MDFN_Error(const MDFN_Error &ze_error) throw(); |
| 23 | MDFN_Error & operator=(const MDFN_Error &ze_error) throw(); |
| 24 | |
| 25 | virtual const char *what(void) const throw(); |
| 26 | int GetErrno(void) const throw(); |
| 27 | |
| 28 | private: |
| 29 | |
| 30 | int errno_code; |
| 31 | char *error_message; |
| 32 | }; |
| 33 | |
| 34 | class ErrnoHolder |
| 35 | { |
| 36 | public: |
| 37 | |
| 38 | ErrnoHolder() |
| 39 | { |
| 40 | local_errno = 0; |
| 41 | local_strerror[0] = 0; |
| 42 | } |
| 43 | |
| 44 | ErrnoHolder(int the_errno) |
| 45 | { |
| 46 | SetErrno(the_errno); |
| 47 | } |
| 48 | |
| 49 | inline int Errno(void) const |
| 50 | { |
| 51 | return(local_errno); |
| 52 | } |
| 53 | |
| 54 | const char *StrError(void) const |
| 55 | { |
| 56 | return(local_strerror); |
| 57 | } |
| 58 | |
| 59 | void operator=(int the_errno) |
| 60 | { |
| 61 | SetErrno(the_errno); |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | |
| 66 | void SetErrno(int the_errno); |
| 67 | |
| 68 | int local_errno; |
| 69 | char local_strerror[256]; |
| 70 | }; |
| 71 | |
| 72 | #endif |
| 73 | |
| 74 | #endif |