coveo::linq
Implementation of .NET-like LINQ operators in C++
exception.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Exception classes used by LINQ operators.
4  *
5  * @copyright 2016-2019, Coveo Solutions Inc.
6  * Distributed under the Apache License, Version 2.0 (see <a href="https://github.com/coveo/linq/blob/master/LICENSE">LICENSE</a>).
7  */
8 
9 #ifndef COVEO_LINQ_EXCEPTION_H
10 #define COVEO_LINQ_EXCEPTION_H
11 
12 #include <stdexcept>
13 
14 namespace coveo {
15 namespace linq {
16 
17 /**
18  * @brief Empty sequence exception.
19  * @headerfile exception.h <coveo/linq/exception.h>
20  *
21  * Subclass of <tt>std::logic_error</tt> used by LINQ operators
22  * that cannot be applied to an empty sequence.
23  *
24  * @see coveo::linq::throw_linq_empty_sequence()
25  */
26 class empty_sequence : public std::logic_error
27 {
28 public:
29  empty_sequence() = delete;
30  using std::logic_error::logic_error;
31 };
32 
33 /**
34  * @brief Out-of-range exception.
35  * @headerfile exception.h <coveo/linq/exception.h>
36  *
37  * Subclass of <tt>std::out_of_range</tt> used by LINQ operators
38  * when going out of a sequence's range.
39  *
40  * @see coveo::linq::throw_linq_out_of_range()
41  */
42 class out_of_range : public std::out_of_range
43 {
44 public:
45  out_of_range() = delete;
46  using std::out_of_range::out_of_range;
47 };
48 
49 /**
50  * @brief Helper function to throw a <tt>coveo::linq::empty_sequence</tt> exception.
51  * @headerfile exception.h <coveo/linq/exception.h>
52  *
53  * Throws an instance of <tt>coveo::linq::empty_sequence</tt> to indicate
54  * that a LINQ operator does not work on the provided empty sequence.
55  * Does not return.
56  *
57  * @see coveo::linq::empty_sequence
58  */
59 template<typename = void>
61  throw empty_sequence("empty_sequence");
62 }
63 
64 /**
65  * @brief Helper function to throw a <tt>coveo::linq::out_of_range</tt> exception.
66  * @headerfile exception.h <coveo/linq/exception.h>
67  *
68  * Throws an instance of <tt>coveo::linq::out_of_range</tt> to indicate
69  * that a LINQ operator has gone outside the range of the provided sequence.
70  * Does not return.
71  *
72  * @see coveo::linq::out_of_range
73  */
74 template<typename = void>
76  throw out_of_range("out_of_range");
77 }
78 
79 } // linq
80 } // coveo
81 
82 #endif // COVEO_LINQ_EXCEPTION_H
void throw_linq_empty_sequence()
Helper function to throw a coveo::linq::empty_sequence exception.
Definition: exception.h:60
void throw_linq_out_of_range()
Helper function to throw a coveo::linq::out_of_range exception.
Definition: exception.h:75
Out-of-range exception.
Definition: exception.h:42
Empty sequence exception.
Definition: exception.h:26