GCC Code Coverage Report


Directory: gridformat/
File: gridformat/common/exceptions.hpp
Date: 2024-11-20 14:41:59
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 2 2 100.0%
Branches: 13 26 50.0%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 /*!
4 * \file
5 * \ingroup Common
6 * \brief Custom exception classes.
7 */
8 #ifndef GRIDFORMAT_COMMON_EXCEPTIONS_HPP_
9 #define GRIDFORMAT_COMMON_EXCEPTIONS_HPP_
10
11 #include <source_location>
12 #include <exception>
13 #include <string_view>
14 #include <string>
15
16 namespace GridFormat {
17
18 //! \addtogroup Common
19 //! \{
20
21 //! Base class for exceptions in GridFormat
22 class Exception : public std::exception {
23 public:
24 714 explicit Exception(std::string_view what,
25 714 const std::source_location loc = std::source_location::current()) {
26
1/2
✓ Branch 1 taken 714 times.
✗ Branch 2 not taken.
714 _what = what;
27
1/2
✓ Branch 1 taken 714 times.
✗ Branch 2 not taken.
714 _what += "\n";
28
4/8
✓ Branch 2 taken 714 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 714 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 714 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 714 times.
✗ Branch 12 not taken.
1428 _what += "\tFunction: " + std::string(loc.function_name()) + "\n";
29
4/8
✓ Branch 2 taken 714 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 714 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 714 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 714 times.
✗ Branch 12 not taken.
714 _what += "\tFile: " + std::string(loc.file_name()) + "\n";
30
3/6
✓ Branch 3 taken 714 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 714 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 714 times.
✗ Branch 10 not taken.
714 _what += "\tLine: " + std::to_string(loc.line()) + "\n";
31 714 }
32
33 46 const char* what() const noexcept override {
34 46 return _what.data();
35 }
36
37 private:
38 std::string _what;
39 };
40
41 class NotImplemented : public Exception {
42 public:
43 using Exception::Exception;
44 };
45
46 class InvalidState : public Exception {
47 public:
48 using Exception::Exception;
49 };
50
51 class ValueError : public Exception {
52 public:
53 using Exception::Exception;
54 };
55
56 class TypeError : public Exception {
57 public:
58 using Exception::Exception;
59 };
60
61 class SizeError : public Exception {
62 public:
63 using Exception::Exception;
64 };
65
66 class IOError : public Exception {
67 public:
68 using Exception::Exception;
69 };
70
71 //! \} group Common
72
73 } // end namespace GridFormat
74
75 #endif // GRIDFORMAT_COMMON_EXCEPTIONS_HPP_
76