exception_handler_pos.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Cross platform
00011 *****************************************************************************/
00012 
00013 #include <ecl/config/ecl.hpp>
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <sstream>
00020 #include <errno.h>
00021 #include <ecl/exceptions/standard_exception.hpp>
00022 #include "../../../include/ecl/devices/detail/exception_handler_pos.hpp"
00023 
00024 /*****************************************************************************
00025 ** Namespaces
00026 *****************************************************************************/
00027 
00028 namespace ecl {
00029 namespace devices {
00030 
00031 /*****************************************************************************
00032 ** Using
00033 *****************************************************************************/
00034 
00035 using std::ostringstream;
00036 using std::string;
00037 using ecl::StandardException;
00038 
00039 
00040 /*****************************************************************************
00041 ** Implementation [Exception Handlers]
00042 *****************************************************************************/
00043 
00044 StandardException open_exception(const char* loc, const std::string& file_name) {
00045         int error_result = errno;
00046         switch (error_result) {
00047                 case ( ENOENT ) : return StandardException(loc, ecl::NotFoundError, file_name + std::string(" could not be found."));
00048                 case ( EINVAL ) : return StandardException(loc, ecl::InvalidArgError, "File mode setting (read/write/append) was incorrectly specified.");
00049                 case ( EACCES ) : return StandardException(loc, ecl::PermissionsError, string("Could not open ")+file_name+string(". Access permission was denied."));
00050                 case ( EFBIG )  : case (EOVERFLOW)  :
00051                                                   return StandardException(loc, ecl::OutOfResourcesError, string("Could not open ")+file_name+string(". File was too large (you need to use alternative api/configuration)."));
00052                 case ( EINTR )  : return StandardException(loc, ecl::InterruptedError, string("Could not open ")+file_name+string(". Interrupted by a signal while opening."));
00053                 case ( EISDIR ) : return StandardException(loc, ecl::InvalidObjectError, string("Could not open ")+file_name+string(". This is a directory and not a file."));
00054                 case ( ELOOP )  : return StandardException(loc, ecl::SystemFailureError, string("Could not open ")+file_name+string(". Very nested symbolic link hell."));
00055                 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."));
00056                 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."));
00057                 case ( ENAMETOOLONG ) : return StandardException(loc, ecl::InvalidArgError, string("Could not open ")+file_name+string(". The file name is too long."));
00058                 case ( ENOMEM ) : return StandardException(loc, ecl::MemoryError, string("Could not open ")+file_name+string(". Insufficient memory."));
00059                 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."));
00060                 case ( ENOTDIR ): return StandardException(loc, ecl::InvalidObjectError, string("Could not open ")+file_name+string(". Pathname invalid (a directory was not a directory)."));
00061                 case ( EROFS )  : return StandardException(loc, ecl::PermissionsError, string("Could not open ")+file_name+string(". Trying to write to a readonly file system."));
00062                 case ( ETXTBSY ): return StandardException(loc, ecl::UsageError, string("Could not open ")+file_name+string(". Trying to write to a currently executing file."));
00063                 default         :
00064                 {
00065                         ostringstream ostream;
00066                         ostream << "Unknown errno " << error_result << " [" << strerror(error_result) << "]";
00067                         return StandardException(loc, UnknownError, ostream.str());
00068                 }
00069         }
00070 }
00071 
00072 
00073 StandardException write_exception(const char* loc) {
00074         int error_result = errno;
00075         switch (error_result) {
00076                 case ( EAGAIN ) : return StandardException(loc, ecl::BlockingError, "The device has been marked non blocking and the write would block.");
00077                 case ( EBADF  ) : case (EINVAL)
00078                                                 : return StandardException(loc, ecl::InvalidObjectError, "The device is not a valid device for writing.");
00079                 case ( EFAULT ) : return StandardException(loc, ecl::OutOfRangeError, "The device's write buffer is outside your accessible address space.");
00080                 case ( EFBIG  ) : return StandardException(loc, ecl::MemoryError, "Tried to write beyond the device's (or process's) size limit.");
00081                 case ( EINTR )  : return StandardException(loc, ecl::InterruptedError, "A signal interrupted the write.");
00082                 case ( EIO    ) : return StandardException(loc, ecl::SystemFailureError, "A low level input-output error occured (possibly beyond your control).");
00083                 case ( ENOSPC ) : return StandardException(loc, ecl::OutOfResourcesError, "The device has no room left for the data you are trying to write.");
00084                 case ( EPIPE  ) : return StandardException(loc, ecl::PermissionsError, "You tried to write to a pipe whose reading end is closed.");
00085                 default         :
00086                 {
00087                         ostringstream ostream;
00088                         ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
00089                         return StandardException(loc, UnknownError, ostream.str());
00090                 }
00091         }
00092 }
00093 
00094 
00095 StandardException read_exception(const char* loc) {
00096         int error_result = errno;
00097         switch (error_result) {
00098                 case ( EAGAIN ) : return StandardException(loc, ecl::BlockingError, "The device has been marked non blocking and the read would block.");
00099                 case ( EBADF  ) : case (EINVAL)
00100                                                 : return StandardException(loc, ecl::PermissionsError, "The device is not a valid device for reading.");
00101                 case ( EFAULT ) : return StandardException(loc, ecl::OutOfRangeError, "The device's read buffer is outside your accessible address space.");
00102                 case ( EINTR )  : return StandardException(loc, ecl::InterruptedError, "A signal interrupted the read.");
00103                 case ( EIO    ) : return StandardException(loc, ecl::SystemFailureError, "A low level input-output error occured (possibly beyond your control).");
00104                 case ( EISDIR ) : return StandardException(loc, ecl::InvalidObjectError, "The file descriptor refers to a directory (not readable).");
00105                 default         :
00106                 {
00107                         ostringstream ostream;
00108                         ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
00109                         return StandardException(loc, UnknownError, ostream.str());
00110                 }
00111         }
00112 }
00113 StandardException sync_exception(const char* loc, const std::string &file_name) {
00114         int error_result = errno;
00115         switch (error_result) {
00116                 case ( EBADF  ) : return StandardException(loc, ecl::InvalidArgError, string("Could not sync ") + file_name + string(", the file descriptor was not valid for writing."));
00117                 case ( EIO  )   : return StandardException(loc, ecl::CloseError, string("Could not sync ") + file_name + string(", could not synchronize while closing."));
00118                 case ( EROFS )  : case ( EINVAL )
00119                                                 : return StandardException(loc, ecl::NotSupportedError, string("Could not sync ") + file_name + string(", file descriptor does not support synchronization."));
00120                 default         :
00121                 {
00122                         ostringstream ostream;
00123                         ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
00124                         return StandardException(loc, UnknownError, ostream.str());
00125                 }
00126         }
00127 }
00128 StandardException close_exception(const char* loc, const std::string &file_name) {
00129         int error_result = errno;
00130         switch (error_result) {
00131                 case ( EBADF  ) : return StandardException(loc, ecl::InvalidArgError, string("Could not close ") + file_name + string(". The associated file descriptor was not valid."));
00132                 case ( EIO  )   : return StandardException(loc, ecl::SystemFailureError, string("Could not close ") + file_name + string(". Closing io problem."));
00133                 case ( EINTR )  : return StandardException(loc, ecl::InterruptedError, string("Could not close ") + file_name + string(". Interrupted by a signal."));
00134                 default         :
00135                 {
00136                         ostringstream ostream;
00137                         ostream << "Unknown error " << error_result << ": " << strerror(error_result) << ".";
00138                         return StandardException(loc, UnknownError, ostream.str());
00139                 }
00140         }
00141 }
00142 
00143 } // namespace devices
00144 } // namespace ecl
00145 
00146 


ecl_devices
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:18:03