Changeset 280 in pacpusframework for trunk/src/FileLib
- Timestamp:
- Mar 20, 2014, 11:59:05 AM (11 years ago)
- Location:
- trunk/src/FileLib/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.