From: Maxime Boucher Date: Sun, 12 May 2013 04:33:07 +0000 (-0700) Subject: Replace CHECK in Range.h by throw std::out_of_range X-Git-Tag: v0.22.0~975 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c524e712ddb5632262f6c8b0b93344923c94dbbb;p=folly.git Replace CHECK in Range.h by throw std::out_of_range Summary: Calling CHECK() in folly will force the program to abort in case of a failure. On the other hand, for range checking, the standard library throws std::out_of_range for many functions. Thus it could be a good idea to throw the same exception in folly so that errors can be handled using try {} catch (...) {} blocks. Test Plan: from fbcode, type: fbconfig -r folly; fbmake opt -j32; fbmake runtests_opt -j 32 What other tests should I run? Reviewed By: tudorb@fb.com FB internal diff: D808204 --- diff --git a/folly/Range.h b/folly/Range.h index 04ea64ef..592aead5 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -322,14 +322,14 @@ public: } void advance(size_type n) { - if (n > size()) { + if (UNLIKELY(n > size())) { throw std::out_of_range("index out of range"); } b_ += n; } void subtract(size_type n) { - if (n > size()) { + if (UNLIKELY(n > size())) { throw std::out_of_range("index out of range"); } e_ -= n; @@ -347,7 +347,7 @@ public: Range subpiece(size_type first, size_type length = std::string::npos) const { - if (first > size()) { + if (UNLIKELY(first > size())) { throw std::out_of_range("index out of range"); } return Range(b_ + first,