Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49610 - in trunk/libs/date_time/test: gregorian local_time posix_time
From: andrey.semashev_at_[hidden]
Date: 2008-11-06 10:43:09


Author: andysem
Date: 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
New Revision: 49610
URL: http://svn.boost.org/trac/boost/changeset/49610

Log:
Fixed exception handling that led to exception type slicing in some cases and simply inefficient code in others.
Text files modified:
   trunk/libs/date_time/test/gregorian/testdate.cpp | 14 +++++++-------
   trunk/libs/date_time/test/gregorian/testdate_input_facet.cpp | 4 ++--
   trunk/libs/date_time/test/gregorian/testfacet.cpp | 4 ++--
   trunk/libs/date_time/test/gregorian/testgreg_serialize.cpp | 8 ++++----
   trunk/libs/date_time/test/gregorian/testparse_date.cpp | 14 +++++++-------
   trunk/libs/date_time/test/local_time/testlocal_time.cpp | 2 +-
   trunk/libs/date_time/test/local_time/testlocal_time_input_facet.cpp | 4 ++--
   trunk/libs/date_time/test/local_time/testposix_time_zone.cpp | 12 ++++++------
   trunk/libs/date_time/test/local_time/testtz_database.cpp | 8 ++++----
   trunk/libs/date_time/test/local_time/testwposix_time_zone.cpp | 12 ++++++------
   trunk/libs/date_time/test/posix_time/testtime.cpp | 4 ++--
   trunk/libs/date_time/test/posix_time/testtime_input_facet.cpp | 4 ++--
   trunk/libs/date_time/test/posix_time/testtime_serialize.cpp | 4 ++--
   13 files changed, 47 insertions(+), 47 deletions(-)

Modified: trunk/libs/date_time/test/gregorian/testdate.cpp
==============================================================================
--- trunk/libs/date_time/test/gregorian/testdate.cpp (original)
+++ trunk/libs/date_time/test/gregorian/testdate.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -136,7 +136,7 @@
     //never reached if working -- but stops compiler warnings :-)
     std::cout << "Oops: " << to_iso_string(d9) << std::endl;
   }
- catch (bad_day_of_month) {
+ catch (bad_day_of_month&) {
     check("day out of range", true);
   }
   try {
@@ -145,7 +145,7 @@
     //never reached if working -- but stops compiler warnings :-)
     std::cout << "Oops: " << to_iso_string(d9) << std::endl;
   }
- catch (bad_day_of_month) {
+ catch (bad_day_of_month&) {
     check("day out of range", true);
   }
 
@@ -155,7 +155,7 @@
     //never reached if working -- but stops compiler warnings :-)
     std::cout << "Oops: " << to_iso_string(d20) << std::endl;
   }
- catch (bad_day_of_month) {
+ catch (bad_day_of_month&) {
     check("day out of range", true);
   }
 
@@ -166,7 +166,7 @@
     //never reached if working -- but stops compiler warnings :-)
     std::cout << "Oops: " << to_iso_string(d21) << std::endl;
   }
- catch (bad_day_of_month) {
+ catch (bad_day_of_month&) {
     check("day out of range", true);
   }
 
@@ -176,7 +176,7 @@
     check("last day of month ok", true);
     std::cout << to_iso_string(d22) << std::endl; //stop compiler warning
   }
- catch (bad_day_of_month) {
+ catch (bad_day_of_month&) {
     check("last day of month -- oops bad exception", false);
   }
 
@@ -187,7 +187,7 @@
     //never reached if working -- but stops compiler warnings :-)
     std::cout << "Oops: " << to_iso_string(d23) << std::endl;
   }
- catch (bad_day_of_month) {
+ catch (bad_day_of_month&) {
     check("day out of range", true);
   }
 
@@ -281,7 +281,7 @@
     date d(neg_infin);
     tm d_tm = to_tm(d);
     check("Exception not thrown (special_value to_tm)", false);
- }catch(std::out_of_range e){
+ }catch(std::out_of_range& e){
     check("Caught expected exception (special_value to_tm)", true);
   }catch(...){
     check("Caught un-expected exception (special_value to_tm)", false);

Modified: trunk/libs/date_time/test/gregorian/testdate_input_facet.cpp
==============================================================================
--- trunk/libs/date_time/test/gregorian/testdate_input_facet.cpp (original)
+++ trunk/libs/date_time/test/gregorian/testdate_input_facet.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -18,7 +18,7 @@
 template<class temporal_type, class exception_type>
 bool failure_test(temporal_type component,
                   const std::string& input,
- exception_type /*except*/,
+ exception_type const& /*except*/,
                   boost::gregorian::date_input_facet* facet)
 {
   using namespace boost::gregorian;
@@ -29,7 +29,7 @@
   try {
     iss >> component;
   }
- catch(exception_type e) {
+ catch(exception_type& e) {
     std::cout << "Expected exception caught: \""
               << e.what() << "\"" << std::endl;
     result = iss.fail(); // failbit must be set to pass test

Modified: trunk/libs/date_time/test/gregorian/testfacet.cpp
==============================================================================
--- trunk/libs/date_time/test/gregorian/testfacet.cpp (original)
+++ trunk/libs/date_time/test/gregorian/testfacet.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -295,7 +295,7 @@
     try{
       ss2 >> m; // misspelled
       check("Bad month exception NOT thrown (misspelled name)", false);
- }catch(bad_month){
+ }catch(bad_month&){
       check("Bad month exception caught (misspelled name)", true);
     }catch(...){
       check("Bad month exception NOT caught (misspelled name)", false);
@@ -324,7 +324,7 @@
     try{
       ss2 >> wd;
       check("Bad weekday exception NOT thrown (misspelled name)", false);
- }catch(bad_weekday){
+ }catch(bad_weekday&){
       check("Bad weekday exception caught (misspelled name)", true);
     }catch(...){
       check("Bad weekday exception NOT caught (misspelled name)", false);

Modified: trunk/libs/date_time/test/gregorian/testgreg_serialize.cpp
==============================================================================
--- trunk/libs/date_time/test/gregorian/testgreg_serialize.cpp (original)
+++ trunk/libs/date_time/test/gregorian/testgreg_serialize.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -71,7 +71,7 @@
     save_to(oa, BOOST_SERIALIZATION_NVP(lkd));
     save_to(oa, BOOST_SERIALIZATION_NVP(fkdb));
     save_to(oa, BOOST_SERIALIZATION_NVP(fkda));
- }catch(archive::archive_exception ae){
+ }catch(archive::archive_exception& ae){
     std::string s(ae.what());
     check("Error writing to archive: " + s, false);
     ofs.close();
@@ -94,7 +94,7 @@
     save_to(oa, lkd);
     save_to(oa, fkdb);
     save_to(oa, fkda);
- }catch(archive::archive_exception ae){
+ }catch(archive::archive_exception& ae){
     std::string s(ae.what());
     check("Error writing to archive: " + s, false);
     ofs.close();
@@ -143,7 +143,7 @@
     ia >> BOOST_SERIALIZATION_NVP(lkd2);
     ia >> BOOST_SERIALIZATION_NVP(fkdb2);
     ia >> BOOST_SERIALIZATION_NVP(fkda2);
- }catch(archive::archive_exception ae){
+ }catch(archive::archive_exception& ae){
     std::string s(ae.what());
     check("Error reading from archive: " + s, false);
     ifs.close();
@@ -166,7 +166,7 @@
     ia >> lkd2;
     ia >> fkdb2;
     ia >> fkda2;
- }catch(archive::archive_exception ae){
+ }catch(archive::archive_exception& ae){
     std::string s(ae.what());
     check("Error reading from archive: " + s, false);
     ifs.close();

Modified: trunk/libs/date_time/test/gregorian/testparse_date.cpp
==============================================================================
--- trunk/libs/date_time/test/gregorian/testparse_date.cpp (original)
+++ trunk/libs/date_time/test/gregorian/testparse_date.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -22,15 +22,15 @@
   try {
     d = from_simple_string(date_spec);
   }
- catch(bad_year by){ // ex: "205-Jan-15"
+ catch(bad_year& by){ // ex: "205-Jan-15"
     result = true;
     output_str = by.what();
   }
- catch(bad_month bm){ // ex: "2005-Jsn-15"
+ catch(bad_month& bm){ // ex: "2005-Jsn-15"
     result = true;
     output_str = bm.what();
   }
- catch(bad_day_of_month bd){ // ex: "2005-Jan-51"
+ catch(bad_day_of_month& bd){ // ex: "2005-Jan-51"
     result = true;
     output_str = bd.what();
   }
@@ -236,7 +236,7 @@
       std::cout << "Shouldn't be reached." <<
         boost::gregorian::to_simple_string(bd) << std::endl;
     }
- catch(boost::gregorian::bad_month){
+ catch(boost::gregorian::bad_month&){
       check("bad spelling 'Jull'", true);
     }
     catch(std::exception& e){
@@ -256,7 +256,7 @@
               << boost::gregorian::to_iso_string(bad_day) << std::endl;
 
   }
- catch(boost::gregorian::bad_day_of_month) { //expected
+ catch(boost::gregorian::bad_day_of_month&) { //expected
     check("check bad day", true);
   }
   catch(std::exception& e) {
@@ -275,7 +275,7 @@
               << boost::gregorian::to_iso_string(bad_day) << std::endl;
 
   }
- catch(boost::gregorian::bad_day_of_month) { //expected
+ catch(boost::gregorian::bad_day_of_month&) { //expected
     check("check bad leap year", true);
   }
   catch(std::exception& e) {
@@ -294,7 +294,7 @@
               << boost::gregorian::to_iso_string(bad_month) << std::endl;
 
   }
- catch(boost::gregorian::bad_month) { //expected
+ catch(boost::gregorian::bad_month&) { //expected
     check("check bad month", true);
   }
   catch(std::exception& e) {

Modified: trunk/libs/date_time/test/local_time/testlocal_time.cpp
==============================================================================
--- trunk/libs/date_time/test/local_time/testlocal_time.cpp (original)
+++ trunk/libs/date_time/test/local_time/testlocal_time.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -288,7 +288,7 @@
         local_date_time ldt(not_a_date_time);
         tm ldt_tm = to_tm(ldt);
         check("Exception not thrown (special_value to_tm)", false);
- }catch(std::out_of_range e){
+ }catch(std::out_of_range& e){
         check("Caught expected exception (special_value to_tm)", true);
       }catch(...){
         check("Caught un-expected exception (special_value to_tm)", false);

Modified: trunk/libs/date_time/test/local_time/testlocal_time_input_facet.cpp
==============================================================================
--- trunk/libs/date_time/test/local_time/testlocal_time_input_facet.cpp (original)
+++ trunk/libs/date_time/test/local_time/testlocal_time_input_facet.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -15,7 +15,7 @@
 template<class temporal_type, class exception_type>
 bool failure_test(temporal_type component,
                   const std::string& input,
- exception_type /*except*/,
+ exception_type const& /*except*/,
                   boost::local_time::local_time_input_facet* facet)
 {
   using namespace boost::local_time;
@@ -26,7 +26,7 @@
   try {
     iss >> component;
   }
- catch(exception_type e) {
+ catch(exception_type& e) {
     std::cout << "Expected exception caught: \""
               << e.what() << "\"" << std::endl;
     result = iss.fail(); // failbit must be set to pass test

Modified: trunk/libs/date_time/test/local_time/testposix_time_zone.cpp
==============================================================================
--- trunk/libs/date_time/test/local_time/testposix_time_zone.cpp (original)
+++ trunk/libs/date_time/test/local_time/testposix_time_zone.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -127,31 +127,31 @@
   try {
     posix_time_zone badz("EST-13");
     check("Exception not thrown: bad UTC offset", false);
- }catch(bad_offset boff){
+ }catch(bad_offset& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
   }
   try {
     posix_time_zone badz("EST-5EDT24:00:01,J124/1:30,J310");
     check("Exception not thrown: bad DST adjust", false);
- }catch(bad_adjustment badj){
+ }catch(bad_adjustment& badj){
     std::string msg(badj.what());
     check("Exception caught: "+msg , true);
   }
   try {
     posix_time_zone badz("EST-5EDT01:00:00,J124/-1:30,J310");
     check("Exception not thrown: bad DST start/end offset", false);
- }catch(bad_offset boff){
+ }catch(bad_offset& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
   }
   try {
     posix_time_zone badz("EST-5EDT01:00:00,J124/1:30,J370");
     check("Exception not thrown: invalid date spec", false);
- }catch(boost::gregorian::bad_day_of_month boff){
+ }catch(boost::gregorian::bad_day_of_month& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
- }catch(boost::gregorian::bad_month boff){
+ }catch(boost::gregorian::bad_month& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
   }catch(...){
@@ -200,7 +200,7 @@
     try{
       check("Non-Julian First/last of month", fl_2.dst_local_start_time(2003) ==
           ptime(date(2003,Mar,1),hours(2)));
- }catch(std::exception e){
+ }catch(std::exception& e){
       check("Expected exception caught for Non-Julian day of 59, in non-leap year (Feb-29)", true);
     }
     check("Non-Julian First/last of month", fl_2.dst_local_end_time(2003) ==

Modified: trunk/libs/date_time/test/local_time/testtz_database.cpp
==============================================================================
--- trunk/libs/date_time/test/local_time/testtz_database.cpp (original)
+++ trunk/libs/date_time/test/local_time/testtz_database.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -32,7 +32,7 @@
   try{
     tz_database tz_db;
     tz_db.load_from_file("missing_file.csv"); // file does not exist
- }catch(data_not_accessible e){
+ }catch(data_not_accessible& e){
     check("Caught Missing data file exception", true);
   }catch(...){
     check("Caught first unexpected exception", false);
@@ -52,7 +52,7 @@
   try {
     // first try to find the data file from the test dir
     tz_db.load_from_file("../data/date_time_zonespec.csv");
- }catch(data_not_accessible e) {
+ }catch(data_not_accessible& e) {
     // couldn't find the data file so assume we are being run from
     // boost_root/status and try again
     tz_db.load_from_file("../libs/date_time/data/date_time_zonespec.csv");
@@ -121,14 +121,14 @@
   tz_database other_db;
   try{
     other_db.load_from_file("local_time/poorly_formed_zonespec.csv");
- }catch(bad_field_count be){
+ }catch(bad_field_count& be){
     caught_bfc = true;
   }catch(...) {
     // do nothing (file not found)
   }
   try{
     other_db.load_from_file("../libs/date_time/test/local_time/poorly_formed_zonespec.csv");
- }catch(bad_field_count be){
+ }catch(bad_field_count& be){
     caught_bfc = true;
   }catch(...) {
     // do nothing (file not found)

Modified: trunk/libs/date_time/test/local_time/testwposix_time_zone.cpp
==============================================================================
--- trunk/libs/date_time/test/local_time/testwposix_time_zone.cpp (original)
+++ trunk/libs/date_time/test/local_time/testwposix_time_zone.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -130,31 +130,31 @@
   try {
     w_posix_time_zone badz(L"EST-13");
     check("Exception not thrown: bad UTC offset", false);
- }catch(bad_offset boff){
+ }catch(bad_offset& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
   }
   try {
     w_posix_time_zone badz(L"EST-5EDT24:00:01,J124/1:30,J310");
     check("Exception not thrown: bad DST adjust", false);
- }catch(bad_adjustment badj){
+ }catch(bad_adjustment& badj){
     std::string msg(badj.what());
     check("Exception caught: "+msg , true);
   }
   try {
     w_posix_time_zone badz(L"EST-5EDT01:00:00,J124/-1:30,J310");
     check("Exception not thrown: bad DST start/end offset", false);
- }catch(bad_offset boff){
+ }catch(bad_offset& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
   }
   try {
     w_posix_time_zone badz(L"EST-5EDT01:00:00,J124/1:30,J370");
     check("Exception not thrown: invalid date spec", false);
- }catch(boost::gregorian::bad_day_of_month boff){
+ }catch(boost::gregorian::bad_day_of_month& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
- }catch(boost::gregorian::bad_month boff){
+ }catch(boost::gregorian::bad_month& boff){
     std::string msg(boff.what());
     check("Exception caught: "+msg , true);
   }catch(...){
@@ -203,7 +203,7 @@
     try{
       check("Non-Julian First/last of month", fl_2.dst_local_start_time(2003) ==
           ptime(date(2003,Mar,1),hours(2)));
- }catch(std::exception e){
+ }catch(std::exception& e){
       check("Expected exception caught for Non-Julian day of 59, in non-leap year (Feb-29)", true);
     }
     check("Non-Julian First/last of month", fl_2.dst_local_end_time(2003) ==

Modified: trunk/libs/date_time/test/posix_time/testtime.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -302,7 +302,7 @@
     ptime pt(pos_infin);
     tm pt_tm = to_tm(pt);
     check("Exception not thrown (special_value to_tm)", false);
- }catch(std::out_of_range e){
+ }catch(std::out_of_range& e){
     check("Caught expected exception (special_value to_tm)", true);
   }catch(...){
     check("Caught un-expected exception (special_value to_tm)", false);
@@ -314,7 +314,7 @@
     pt += time_duration(pos_infin);
     tm pt_tm = to_tm(pt);
     check("Exception not thrown (special_value to_tm)", false);
- }catch(std::out_of_range e){
+ }catch(std::out_of_range& e){
     check("Caught expected exception (special_value to_tm)", true);
   }catch(...){
     check("Caught un-expected exception (special_value to_tm)", false);

Modified: trunk/libs/date_time/test/posix_time/testtime_input_facet.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime_input_facet.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime_input_facet.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -18,7 +18,7 @@
 template<class temporal_type, class exception_type>
 bool failure_test(temporal_type component,
                   const std::string& input,
- exception_type /*except*/,
+ exception_type const& /*except*/,
                   boost::posix_time::time_input_facet* facet)
 {
   using namespace boost::posix_time;
@@ -29,7 +29,7 @@
   try {
     iss >> component;
   }
- catch(exception_type e) {
+ catch(exception_type& e) {
     std::cout << "Expected exception caught: \""
               << e.what() << "\"" << std::endl;
     result = iss.fail(); // failbit must be set to pass test

Modified: trunk/libs/date_time/test/posix_time/testtime_serialize.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime_serialize.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime_serialize.cpp 2008-11-06 10:43:07 EST (Thu, 06 Nov 2008)
@@ -75,7 +75,7 @@
     save_to(oa, td);
     save_to(oa, sv_td);
 #endif // DATE_TIME_XML_SERIALIZE
- }catch(archive::archive_exception ae){
+ }catch(archive::archive_exception& ae){
     std::string s(ae.what());
     check("Error writing to archive: " + s, false);
     ofs.close();
@@ -107,7 +107,7 @@
     ia >> td2;
     ia >> sv_td2;
 #endif // DATE_TIME_XML_SERIALIZE
- }catch(archive::archive_exception ae){
+ }catch(archive::archive_exception& ae){
     std::string s(ae.what());
     check("Error readng from archive: " + s, false);
     ifs.close();


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk