From 5b0c36c9c6c9c30f1eb42186fed7acc7e99faf3e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 21 Dec 2009 07:27:10 +0000 Subject: [PATCH] Add LogicError exception class Throw InvalidState in DateTime::get_timestamp for out-of-range values --- source/core/except.h | 9 +++++++++ source/time/datetime.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/core/except.h b/source/core/except.h index bf7c526..6d34d4b 100644 --- a/source/core/except.h +++ b/source/core/except.h @@ -97,6 +97,15 @@ private: static std::string build_what(const std::string &, int); }; +/** +Thrown when "impossible" things happen. +*/ +class LogicError: public Exception +{ +public: + LogicError(const std::string &w_): Exception(w_) { } +}; + template void throw_at(E e, const std::string &a) { e.at(a); throw e; } diff --git a/source/time/datetime.cpp b/source/time/datetime.cpp index 2c6fcea..8623886 100644 --- a/source/time/datetime.cpp +++ b/source/time/datetime.cpp @@ -203,7 +203,7 @@ int DateTime::cmp(const DateTime &dt) const TimeStamp DateTime::get_timestamp() const { if(year<-289701 || year>293641) - throw Exception("DateTime is not representable as a TimeStamp"); + throw InvalidState("DateTime is not representable as a TimeStamp"); RawTime raw=(((hour*60LL)+minute)*60+second)*1000000+usec; int days=(year-1970)*365; -- 2.45.2