GCC Code Coverage Report


./
File: mrubyexception.hpp
Date: 2024-05-21 01:02:25
Lines:
43/48
89.6%
Functions:
14/16
87.5%
Branches:
23/48
47.9%

Line Branch Exec Source
1 #ifndef __MRUBYEXCEPTION_HPP__
2 #define __MRUBYEXCEPTION_HPP__
3
4 #include <string>
5 #include <sstream>
6
7 class Exception : public std::exception
8 {
9 public:
10 2 Exception(const std::string &type, const std::string &msg, const std::string &name)
11 2 {
12
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 std::stringstream s;
13
5/10
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
2 s << type << ": " << msg << ": " << name;
14
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 error = s.str();
15 2 }
16
17 4 virtual ~Exception()
18 4 { }
19
20 2 const char *what() const noexcept
21 {
22 2 return error.c_str();
23 }
24 protected:
25 std::string error;
26 };
27
28 // Exceptions that occur outside the VM
29
30 class NameError : public Exception
31 {
32 public:
33 2 NameError(const std::string &msg, const std::string &name)
34
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 : Exception("NameError", msg, name)
35 2 { }
36
37 4 virtual ~NameError()
38 4 { }
39
40 };
41
42 class NotImplementedError : public Exception
43 {
44 public:
45 NotImplementedError(const std::string &msg, const std::string &name)
46 : Exception("NotImplementedError", msg, name)
47 { }
48
49 virtual ~NotImplementedError()
50 { }
51
52 };
53
54 class TypeError : public Exception
55 {
56 public:
57 TypeError(const std::string &msg, const std::string &name)
58 : Exception("TypeError", msg, name)
59 { }
60
61 virtual ~TypeError()
62 { }
63
64 };
65
66 class ArgumentError : public Exception
67 {
68 public:
69 ArgumentError(const std::string &msg, const std::string &name)
70 : Exception("ArgumentError", msg, name)
71 { }
72
73 virtual ~ArgumentError()
74 { }
75
76 };
77
78 // Exceptions that occur inside the VM
79 class RubyException : public std::exception
80 {
81 public:
82 1 RubyException()
83
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 : error("Exception in C binding")
84 1 { }
85
86 7 RubyException(const std::string &type, const std::string &msg)
87 7 {
88
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 std::stringstream s;
89
2/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
7 s << type << " in C binding";
90
3/4
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 2 times.
7 if (msg != "")
91 {
92
2/4
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 s << ": " << msg;
93 }
94
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
7 error = s.str();
95 7 }
96
97 16 virtual ~RubyException()
98 16 { }
99
100 16 const char *what() const noexcept
101 {
102 16 return error.c_str();
103 }
104 protected:
105 std::string error;
106 };
107
108 class RubyStandardError : public RubyException
109 {
110 public:
111 1 RubyStandardError(const std::string &msg="")
112
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 : RubyException("StandardError", msg)
113 1 { }
114
115 14 virtual ~RubyStandardError()
116 14 { }
117
118 protected:
119 6 RubyStandardError(const std::string &type, const std::string &msg)
120 6 : RubyException(type, msg)
121 6 { }
122 };
123
124 class RubyRuntimeError : public RubyStandardError
125 {
126 public:
127 6 RubyRuntimeError(const std::string &msg="")
128
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
12 : RubyStandardError("RuntimeError", msg)
129 6 { }
130
131 12 virtual ~RubyRuntimeError()
132 12 { }
133
134 };
135 #endif // __MRUBYEXCEPTION_HPP__
136