libtasks Documentation  1.6
error_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #ifndef _TASKS_ERROR_BASE_H_
9 #define _TASKS_ERROR_BASE_H_
10 
11 #include <string>
12 #include <cstring>
13 #include <tasks/tasks_exception.h>
14 
15 namespace tasks {
16 
18 class error_base {
19  public:
21  virtual ~error_base() {}
22 
24  inline bool error() const {
26  }
27 
29  inline tasks_error error_code() const {
30  return m_exception.error_code();
31  }
32 
34  inline const std::string& error_message() const {
35  return m_exception.message();
36  }
37 
39  inline int sys_errno() const {
40  return m_exception.sys_errno();
41  }
42 
44  inline std::string sys_errno_str() const {
45  return std::strerror(sys_errno());
46  }
47 
49  inline const tasks_exception& exception() const {
50  return m_exception;
51  }
52 
54  inline void set_exception(tasks_exception& e) {
55  m_exception = e;
56  }
57 
59  inline void reset_error() {
61  }
62 
63  private:
65 };
66 
67 } // tasks
68 
69 #endif // _TASKS_ERROR_BASE_H_
void reset_error()
Reset the error state.
Definition: error_base.h:59
int sys_errno() const
Return the errno if available.
Definition: error_base.h:39
tasks_exception m_exception
Definition: error_base.h:64
tasks_error error_code() const
Return the error code.
Definition: error_base.h:29
bool error() const
Return true if an error occured.
Definition: error_base.h:24
A helper class for basic error reporting.
Definition: error_base.h:18
void reset()
Reset the exception.
Tasks execption class.
const std::string & error_message() const
Return the error message.
Definition: error_base.h:34
int sys_errno() const noexcept
Return the errno if available.
std::string sys_errno_str() const
Return the errno description if available.
Definition: error_base.h:44
const std::string & message() const noexcept
Return the error message.
void set_exception(tasks_exception &e)
Set an exception to report an error.
Definition: error_base.h:54
tasks_error error_code() const noexcept
Return the error code.
const tasks_exception & exception() const
Return the underlying exception object.
Definition: error_base.h:49
virtual ~error_base()
Definition: error_base.h:21