- Timestamp:
- Mar 20, 2014, 11:59:05 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/Pacpus/kernel/DbiteException.h
r156 r280 18 18 #include <Pacpus/kernel/PacpusException.h> 19 19 20 #include <ios> 20 21 #include <string> 21 22 … … 29 30 /// Ctor. 30 31 /// @param what Information about the exception. 31 DbiteException( const std::string & what);32 DbiteException(std::string const& what = ""); 32 33 33 34 /// Dtor. … … 35 36 }; 36 37 38 typedef boost::error_info<struct tag_errinfo_ios_base_open_mode, std::ios_base::openmode> errinfo_ios_base_open_mode; 39 37 40 } // namespace pacpus 38 41 -
trunk/include/Pacpus/kernel/PacpusException.h
r156 r280 17 17 #include <Pacpus/kernel/PacpusLibConfig.h> 18 18 19 //#include <boost/exception/exception.hpp> 19 #include <boost/exception/exception.hpp> 20 #include <boost/exception/error_info.hpp> 20 21 #include <exception> 21 22 #include <string> … … 23 24 #ifdef _MSC_VER 24 25 # pragma warning(push) 25 # pragma warning(disable: 4251 )26 # pragma warning(disable: 4251 4275) 26 27 #endif // _MSC_VER 27 28 28 namespace pacpus { 29 namespace pacpus 30 { 29 31 30 32 /// Base class for all exceptions in the framework 31 33 class PACPUSLIB_API PacpusException 32 : virtual public std::exception33 //, virtual public boost::exception34 : /*virtual*/ public std::runtime_error 35 , virtual public boost::exception 34 36 { 35 37 public: 36 38 /// Ctor. 37 39 /// @param what Information about the exception. 38 PacpusException( const std::string & what);40 PacpusException(std::string const& what = ""); 39 41 40 42 /// Dtor. 41 virtual ~PacpusException() throw(); 42 43 /// Gets more information about the error. 44 /// 45 /// @returns Message containing information about the error. 46 virtual const char * what() const throw(); 47 48 protected: 49 std::string mWhat; 43 virtual ~PacpusException(); 50 44 }; 51 45 52 46 } // namespace pacpus 47 48 typedef boost::error_info<struct tag_errinfo_signal, int> errinfo_signal; 53 49 54 50 #ifdef _MSC_VER -
trunk/src/FileLib/src/DbiteException.cpp
r156 r280 10 10 using namespace pacpus; 11 11 12 DbiteException::DbiteException( const std::string& what)12 DbiteException::DbiteException(std::string const& what) 13 13 : PacpusException(what) 14 14 { -
trunk/src/FileLib/src/DbiteFile.cpp
r141 r280 10 10 #include <Pacpus/kernel/Log.h> 11 11 12 #include <boost/exception/detail/exception_ptr.hpp> 13 #include <boost/exception/errinfo_api_function.hpp> 14 #include <boost/exception/errinfo_file_name.hpp> 15 #include <boost/exception/errinfo_nested_exception.hpp> 12 16 #include <cassert> 13 17 #include <cmath> … … 16 20 #include <sstream> 17 21 22 using boost::copy_exception; 23 using boost::errinfo_api_function; 24 using boost::errinfo_file_name; 25 using boost::errinfo_nested_exception; 26 using boost::exception_ptr; 18 27 using namespace pacpus; 19 using namespace std; 28 using std::fstream; 29 using std::ios_base; 30 using std::min; 31 using std::max; 32 using std::numeric_limits; 33 using std::streamsize; 34 using std::string; 35 using std::stringstream; 20 36 21 37 // FIXME: record size is only 8-bit long! … … 32 48 } 33 49 34 bool doesFileExist( const string& path);50 bool doesFileExist(string const& path); 35 51 36 52 DbiteFile::DbiteFile() … … 57 73 stringstream os; 58 74 59 os << "Signature : " << getSignature() << endl;60 os << "Version : " << getVersion() << endl;61 os << "Header size : " << getDataOffset() << " [bytes]" << endl;62 os << "Record size : " << getRecordSize() << " [bytes]" << endl;63 os << "Data type : " << getType() << endl;64 os << "Time min. : " << getTimeMin() << endl;65 os << "Time max. : " << getTimeMax() << endl;66 os << "Duration : " << (getTimeMax() - getTimeMin()) / kMicrosInSecond << " [seconds]" << endl;67 os << "File size : " << getFileSize() << " [bytes]" << endl;68 os << "Record count : " << getRecordCount() << endl;75 os << "Signature : " << getSignature() << "\n"; 76 os << "Version : " << getVersion() << "\n"; 77 os << "Header size : " << getDataOffset() << " [bytes]" << "\n"; 78 os << "Record size : " << getRecordSize() << " [bytes]" << "\n"; 79 os << "Data type : " << getType() << "\n"; 80 os << "Time min. : " << getTimeMin() << "\n"; 81 os << "Time max. : " << getTimeMax() << "\n"; 82 os << "Duration : " << (getTimeMax() - getTimeMin()) / kMicrosInSecond << " [seconds]" << "\n"; 83 os << "File size : " << getFileSize() << " [bytes]" << "\n"; 84 os << "Record count : " << getRecordCount() << "\n"; 69 85 70 86 return os.str(); … … 91 107 setPath(path); 92 108 93 mFile.open(getPath().c_str(), ios_base::binary | ios_base::in); 109 ios_base::openmode openmode = ios_base::binary | ios_base::in; 110 mFile.open(getPath().c_str(), openmode); 94 111 try { 95 112 checkFileOpen(); … … 98 115 LOG_ERROR("Dbite exception: " << e.what()); 99 116 close(); 100 throw DbiteException("cannot open file for reading"); 117 BOOST_THROW_EXCEPTION(DbiteException("cannot open file for reading") 118 << errinfo_file_name(mPath) 119 << errinfo_ios_base_open_mode(openmode) 120 ); 101 121 } 102 122 103 123 try { 104 124 readHeader(); 105 } catch (DbiteException 125 } catch (DbiteException& e) { 106 126 (void) e; // unused 107 127 LOG_ERROR("Dbite exception: " << e.what()); 108 128 // TODO: readAndDiagnoseHeader(); 109 129 close(); 110 throw DbiteException("cannot read header"); 130 BOOST_THROW_EXCEPTION(DbiteException("cannot read header") 131 << errinfo_nested_exception(copy_exception(e)) 132 ); 111 133 } 112 134 verifyHeader(); … … 156 178 if (!isOpen()) { 157 179 LOG_ERROR("cannot open file for writing"); 158 throw DbiteException("cannot open file for writing"); 180 BOOST_THROW_EXCEPTION(DbiteException("cannot open file for writing") 181 << errinfo_ios_base_open_mode(openmode) 182 ); 159 183 } 160 184 … … 170 194 // TODO: readAndDiagnoseHeader(); 171 195 close(); 172 throw DbiteException("cannot read header");196 BOOST_THROW_EXCEPTION(DbiteException("cannot read header")); 173 197 } 174 198 } else { … … 336 360 if (getVersion() != VERSION_NUMBER) { 337 361 LOG_ERROR("bad version number"); 338 throw DbiteException("bad version number");362 BOOST_THROW_EXCEPTION(DbiteException("bad version number")); 339 363 } 340 364 341 365 if (!isSignatureCorrect()) { 342 366 LOG_ERROR("bad signature"); 343 throw DbiteException("bad signature");367 BOOST_THROW_EXCEPTION(DbiteException("bad signature")); 344 368 } 345 369 … … 511 535 if (isVariableDataSize()) { 512 536 LOG_ERROR("cannot read nth record in a variable"); 513 throw DbiteException("cannot read nth record in a variable");537 BOOST_THROW_EXCEPTION(DbiteException("cannot read nth record in a variable")); 514 538 } 515 539 … … 518 542 if (getFileSize() < nthRecordPosition) { 519 543 LOG_WARN("wanted to read past the file end"); 520 // throw DbiteException("wanted to read past the file end");544 //BOOST_THROW_EXCEPTION(DbiteException("wanted to read past the file end")); 521 545 } 522 546 mFile.clear(); … … 530 554 if (!buffer) { 531 555 LOG_WARN("data buffer must be a non-NULL pointer"); 532 throw DbiteException("data buffer must be a non-NULL pointer");556 BOOST_THROW_EXCEPTION(DbiteException("data buffer must be a non-NULL pointer")); 533 557 } 534 558 … … 582 606 } 583 607 LOG_ERROR("cannot read acquisition time"); 584 throw DbiteException("cannot read acquisition time"); 608 BOOST_THROW_EXCEPTION(DbiteException("cannot read acquisition time") 609 << errinfo_file_name(mPath) 610 << errinfo_api_function("read") 611 ); 585 612 } 586 613 … … 613 640 LOG_INFO("buffer size = " << bufferSize); 614 641 LOG_INFO("data size = " << dataSize); 615 throw DbiteException("buffer is smaller than the data size");642 BOOST_THROW_EXCEPTION(DbiteException("buffer is smaller than the data size")); 616 643 // TODO: don't throw exception, but read only as much data as possible 617 644 } … … 682 709 // read forward 683 710 readResult = readRecordForward(time, timeRange, buffer, bufferSize); 684 } catch (DbiteException & e) {711 } catch (DbiteException& /*e*/) { 685 712 setReadPosition(initialPosition); 686 throw e;713 throw; 687 714 } 688 715 … … 703 730 if (dataSize > static_cast<size_t>(numeric_limits<VariableDataSizeT>::max())) { 704 731 LOG_ERROR("variable data size too big"); 705 throw DbiteException("variable data size too big"); 732 BOOST_THROW_EXCEPTION(DbiteException("variable data size too big") 733 << errinfo_file_name(mPath) 734 ); 706 735 } 707 736 } … … 734 763 writtenBytes += sizeof(VariableDataSizeT); 735 764 } 736 } catch (DbiteException 765 } catch (DbiteException& e) { 737 766 LOG_ERROR("Dbite exception: " << e.what()); 738 767 LOG_INFO("restoring initial write position"); … … 740 769 // on error, go back to record start 741 770 setWritePosition(- (int64_t) writtenBytes, ios_base::cur); 742 throw e;771 throw; 743 772 } 744 773 … … 766 795 if (!mFile) { 767 796 LOG_ERROR("cannot read data"); 768 throw DbiteException("cannot read data"); 797 BOOST_THROW_EXCEPTION(DbiteException("cannot read data") 798 << errinfo_file_name(mPath) 799 << errinfo_api_function("read") 800 ); 769 801 } 770 802 } … … 775 807 if (!mFile) { 776 808 LOG_ERROR("cannot write data"); 777 throw DbiteException("cannot write data"); 809 BOOST_THROW_EXCEPTION(DbiteException("cannot write data") 810 << errinfo_file_name(mPath) 811 << errinfo_api_function("write") 812 ); 778 813 } 779 814 } … … 789 824 string errorMessage = "file is not open"; 790 825 LOG_WARN(errorMessage); 791 throw DbiteException(errorMessage.c_str()); 826 BOOST_THROW_EXCEPTION(DbiteException(errorMessage.c_str()) 827 << errinfo_file_name(mPath) 828 ); 792 829 } 793 830 } -
trunk/src/PacpusLib/ComponentBase.cpp
r279 r280 509 509 } catch (po::error& e) { 510 510 LOG_WARN(e.what()); 511 throw PacpusException(e.what());511 BOOST_THROW_EXCEPTION(PacpusException(e.what())); 512 512 } 513 513 -
trunk/src/PacpusLib/PacpusApplication.cpp
r222 r280 89 89 try { 90 90 return QApplication::notify(receiver, ev); 91 } catch (PacpusException 91 } catch (PacpusException& e) { 92 92 (void)e; // unused 93 LOG_ERROR("PacpusException thrown:" << e.what() );94 } catch (boost::exception 93 LOG_ERROR("PacpusException thrown:" << e.what() << "\n" << boost::diagnostic_information(e)); 94 } catch (boost::exception& e) { 95 95 (void)e; // unused 96 96 LOG_ERROR("boost::exception thrown:" << boost::diagnostic_information(e)); 97 } catch (std::exception 97 } catch (std::exception& e) { 98 98 (void)e; // unused 99 99 LOG_ERROR("std::exception thrown:" << e.what()); … … 125 125 std::stringstream errorMessage; 126 126 errorMessage << "received signal number " << signal; 127 throw PacpusException(errorMessage.str()); 127 BOOST_THROW_EXCEPTION(PacpusException(errorMessage.str()) 128 << errinfo_signal(signal) 129 ); 128 130 } -
trunk/src/PacpusLib/PacpusException.cpp
r156 r280 10 10 using namespace pacpus; 11 11 12 PacpusException::PacpusException( const std::string& what)13 : mWhat(what)12 PacpusException::PacpusException(std::string const& what) 13 : std::runtime_error(what) 14 14 { 15 15 } 16 16 17 PacpusException::~PacpusException() throw()17 PacpusException::~PacpusException() 18 18 { 19 19 } 20 21 const char * PacpusException::what() const throw()22 {23 return mWhat.c_str();24 } -
trunk/src/PacpusLib/XmlConfigFile.cpp
r231 r280 8 8 9 9 #include <Pacpus/kernel/Log.h> 10 #include <Pacpus/kernel/PacpusException.h> 10 11 11 12 #include <cassert> … … 67 68 } else { 68 69 LOG_ERROR("cannot open XML document " << kXmlConfigFilename); 69 throw "cannot open XML document file";70 BOOST_THROW_EXCEPTION(PacpusException("cannot open XML document file")); 70 71 } 71 72 }
Note:
See TracChangeset
for help on using the changeset viewer.