exception_handler_pos.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Cross platform
11 *****************************************************************************/
12 
13 #include <ecl/config/ecl.hpp>
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <sstream>
20 #include <errno.h>
22 #include "../../../include/ecl/devices/detail/exception_handler_pos.hpp"
23 
24 /*****************************************************************************
25 ** Namespaces
26 *****************************************************************************/
27 
28 namespace ecl {
29 namespace devices {
30 
31 /*****************************************************************************
32 ** Using
33 *****************************************************************************/
34 
35 using std::ostringstream;
36 using std::string;
38 
39 
40 /*****************************************************************************
41 ** Implementation [Exception Handlers]
42 *****************************************************************************/
43 
44 StandardException open_exception(const char* loc, const std::string& file_name) {
45  int error_result = errno;
46  switch (error_result) {
47  case ( ENOENT ) : return StandardException(loc, ecl::NotFoundError, file_name + std::string(" could not be found."));
48  case ( EINVAL ) : return StandardException(loc, ecl::InvalidArgError, "File mode setting (read/write/append) was incorrectly specified.");
49  case ( EACCES ) : return StandardException(loc, ecl::PermissionsError, string("Could not open ")+file_name+string(". Access permission was denied."));
50  case ( EFBIG ) : case (EOVERFLOW) :
51  return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". File was too large (you need to use alternative api/configuration)."));
52  case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, string("Could not open ")+file_name+string(". Interrupted by a signal while opening."));
53  case ( EISDIR ) : return StandardException(loc, ecl::InvalidObjectError, string("Could not open ")+file_name+string(". This is a directory and not a file."));
54  case ( ELOOP ) : return StandardException(loc, ecl::SystemFailureError, string("Could not open ")+file_name+string(". Very nested symbolic link hell."));
55  case ( EMFILE ) : return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". This process has already maxxed out its permitted number of open files."));
56  case ( ENFILE ) : return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". This system has already maxxed out its permitted number of open files."));
57  case ( ENAMETOOLONG ) : return StandardException(loc, ecl::InvalidArgError, string("Could not open ")+file_name+string(". The file name is too long."));
58  case ( ENOMEM ) : return StandardException(loc, ecl::MemoryError, string("Could not open ")+file_name+string(". Insufficient memory."));
59  case ( ENOSPC ) : return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". The container device (usually hard disk) has insufficient space to create the file."));
60  case ( ENOTDIR ): return StandardException(loc, ecl::InvalidObjectError, string("Could not open ")+file_name+string(". Pathname invalid (a directory was not a directory)."));
61  case ( EROFS ) : return StandardException(loc, ecl::PermissionsError, string("Could not open ")+file_name+string(". Trying to write to a readonly file system."));
62  case ( ETXTBSY ): return StandardException(loc, ecl::UsageError, string("Could not open ")+file_name+string(". Trying to write to a currently executing file."));
63  default :
64  {
65  ostringstream ostream;
66  ostream << "Unknown errno " << error_result << " [" << strerror(error_result) << "]";
67  return StandardException(loc, UnknownError, ostream.str());
68  }
69  }
70 }
71 
72 
74  int error_result = errno;
75  switch (error_result) {
76  case ( EAGAIN ) : return StandardException(loc, ecl::BlockingError, "The device has been marked non blocking and the write would block.");
77  case ( EBADF ) : case (EINVAL)
78  : return StandardException(loc, ecl::InvalidObjectError, "The device is not a valid device for writing.");
79  case ( EFAULT ) : return StandardException(loc, ecl::OutOfRangeError, "The device's write buffer is outside your accessible address space.");
80  case ( EFBIG ) : return StandardException(loc, ecl::MemoryError, "Tried to write beyond the device's (or process's) size limit.");
81  case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "A signal interrupted the write.");
82  case ( EIO ) : return StandardException(loc, ecl::SystemFailureError, "A low level input-output error occured (possibly beyond your control).");
83  case ( ENOSPC ) : return StandardException(loc, ecl::OutOfResourcesError, "The device has no room left for the data you are trying to write.");
84  case ( EPIPE ) : return StandardException(loc, ecl::PermissionsError, "You tried to write to a pipe whose reading end is closed.");
85  default :
86  {
87  ostringstream ostream;
88  ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
89  return StandardException(loc, UnknownError, ostream.str());
90  }
91  }
92 }
93 
94 
96  int error_result = errno;
97  switch (error_result) {
98  case ( EAGAIN ) : return StandardException(loc, ecl::BlockingError, "The device has been marked non blocking and the read would block.");
99  case ( EBADF ) : case (EINVAL)
100  : return StandardException(loc, ecl::PermissionsError, "The device is not a valid device for reading.");
101  case ( EFAULT ) : return StandardException(loc, ecl::OutOfRangeError, "The device's read buffer is outside your accessible address space.");
102  case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, "A signal interrupted the read.");
103  case ( EIO ) : return StandardException(loc, ecl::SystemFailureError, "A low level input-output error occured (possibly beyond your control).");
104  case ( EISDIR ) : return StandardException(loc, ecl::InvalidObjectError, "The file descriptor refers to a directory (not readable).");
105  default :
106  {
107  ostringstream ostream;
108  ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
109  return StandardException(loc, UnknownError, ostream.str());
110  }
111  }
112 }
113 StandardException sync_exception(const char* loc, const std::string &file_name) {
114  int error_result = errno;
115  switch (error_result) {
116  case ( EBADF ) : return StandardException(loc, ecl::InvalidArgError, string("Could not sync ") + file_name + string(", the file descriptor was not valid for writing."));
117  case ( EIO ) : return StandardException(loc, ecl::CloseError, string("Could not sync ") + file_name + string(", could not synchronize while closing."));
118  case ( EROFS ) : case ( EINVAL )
119  : return StandardException(loc, ecl::NotSupportedError, string("Could not sync ") + file_name + string(", file descriptor does not support synchronization."));
120  default :
121  {
122  ostringstream ostream;
123  ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
124  return StandardException(loc, UnknownError, ostream.str());
125  }
126  }
127 }
128 StandardException close_exception(const char* loc, const std::string &file_name) {
129  int error_result = errno;
130  switch (error_result) {
131  case ( EBADF ) : return StandardException(loc, ecl::InvalidArgError, string("Could not close ") + file_name + string(". The associated file descriptor was not valid."));
132  case ( EIO ) : return StandardException(loc, ecl::SystemFailureError, string("Could not close ") + file_name + string(". Closing io problem."));
133  case ( EINTR ) : return StandardException(loc, ecl::InterruptedError, string("Could not close ") + file_name + string(". Interrupted by a signal."));
134  default :
135  {
136  ostringstream ostream;
137  ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
138  return StandardException(loc, UnknownError, ostream.str());
139  }
140  }
141 }
142 
143 } // namespace devices
144 } // namespace ecl
145 
146 
Embedded control libraries.
StandardException read_exception(const char *loc)
InvalidObjectError
InterruptedError
PermissionsError
CloseError
InvalidArgError
NotSupportedError
UnknownError
StandardException open_exception(const char *loc, const std::string &file_name)
OutOfRangeError
BlockingError
NotFoundError
StandardException sync_exception(const char *loc, const std::string &file_name)
OutOfResourcesError
UsageError
StandardException close_exception(const char *loc, const std::string &file_name)
StandardException write_exception(const char *loc)
SystemFailureError
MemoryError


ecl_devices
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:45