libtasks Documentation  1.6
tasks_exception.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_TASKS_EXCEPTION_H_
9 #define _TASKS_TASKS_EXCEPTION_H_
10 
11 #include <string>
12 #include <sstream>
13 
14 namespace tasks {
15 
16 enum class tasks_error {
60  TERM_OPEN,
61  TERM_FCNTL,
69  UNSET
70 };
71 
73 class tasks_exception : public std::exception {
74  public:
77 
79  tasks_exception(tasks_error error, std::string what, int sys_errno)
80  : m_error(error), m_what(what), m_sys_errno(sys_errno) {}
81 
83  tasks_exception(tasks_error error, std::string what) : m_error(error), m_what(what) {}
84 
86  tasks_error error_code() const noexcept {
87  return m_error;
88  }
89 
91  int sys_errno() const noexcept {
92  return m_sys_errno;
93  }
94 
96  const std::string& message() const noexcept {
97  return m_what;
98  }
99 
101  const char* what() const noexcept {
102  return m_what.c_str();
103  }
104 
106  void reset() {
108  m_what = "";
109  m_sys_errno = 0;
110  }
111 
112  private:
114  std::string m_what;
115  int m_sys_errno = 0;
116 };
117 
118 // Keep old exception classes for backward compatibility
119 namespace net {
122 }
123 namespace serial {
125 }
126 
127 } // tasks
128 
129 #endif // _TASKS_TASKS_EXCEPTION_H_
Error on sendto sys call.
Error on chmod sys call (domain sockets)
Error on setsockopt sys call.
tasks_exception(tasks_error error, std::string what)
Construct an object by error_code and message.
tasks_exception()
Default contructor.
void reset()
Reset the exception.
Error on bind sys call.
Error on fnctl sys call.
Tasks execption class.
int sys_errno() const noexcept
Return the errno if available.
Error when calling listen on a UDP socket.
tasks_exception socket_exception
Error on setsockopt sys call.
Error on listen sys call.
tasks_exception http_exception
Error on connect sys call.
tasks_exception(tasks_error error, std::string what, int sys_errno)
Contruct an object by error_code, message and errno.
const std::string & message() const noexcept
Return the error message.
const char * what() const noexcept
Return the error message.
Error when reading from a disconnected socket.
Error on accept sys call.
tasks_exception term_exception
tasks_error error_code() const noexcept
Return the error code.
Error on recvfrom sys call.
Error on socket sys call.
Error on chunked encoding, that is not available yet.
Error when trying to connect to a host that can't be resolved.