Browse Source

Added some better error output for basic parsers using errno

tempestpy_adaptions
gereon 12 years ago
parent
commit
341dc50ab7
  1. 13
      src/parser/Parser.cpp

13
src/parser/Parser.cpp

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <cerrno>
#include "src/exceptions/FileIoException.h" #include "src/exceptions/FileIoException.h"
#include "src/exceptions/WrongFileFormatException.h" #include "src/exceptions/WrongFileFormatException.h"
@ -75,21 +76,21 @@ storm::parser::MappedFile::MappedFile(const char* filename) {
#else #else
if (stat64(filename, &(this->st)) != 0) { if (stat64(filename, &(this->st)) != 0) {
#endif #endif
LOG4CPLUS_ERROR(logger, "Error in stat(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in stat()");
LOG4CPLUS_ERROR(logger, "Error in stat(" << filename << "): " << std::strerror(errno));
throw exceptions::FileIoException() << "storm::parser::MappedFile Error in stat(): " << std::strerror(errno);
} }
this->file = open(filename, O_RDONLY); this->file = open(filename, O_RDONLY);
if (this->file < 0) { if (this->file < 0) {
LOG4CPLUS_ERROR(logger, "Error in open(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in open()");
LOG4CPLUS_ERROR(logger, "Error in open(" << filename << "): " << std::strerror(errno));
throw exceptions::FileIoException() << "storm::parser::MappedFile Error in open(): " << std::strerror(errno);
} }
this->data = reinterpret_cast<char*>(mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0)); this->data = reinterpret_cast<char*>(mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0));
if (this->data == reinterpret_cast<char*>(-1)) { if (this->data == reinterpret_cast<char*>(-1)) {
close(this->file); close(this->file);
LOG4CPLUS_ERROR(logger, "Error in mmap(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in mmap()");
LOG4CPLUS_ERROR(logger, "Error in mmap(" << filename << "): " << std::strerror(errno));
throw exceptions::FileIoException() << "storm::parser::MappedFile Error in mmap(): " << std::strerror(errno);
} }
this->dataend = this->data + this->st.st_size; this->dataend = this->data + this->st.st_size;
#elif defined WINDOWS #elif defined WINDOWS

Loading…
Cancel
Save