Skip to content

Commit 8aef3fa

Browse files
author
Dale Wilson
committed
Throw objects derived from std::exception rather than throwing c-style strings.
Add error numbers to messages to distinguish between identical error message texts. (ex: "buffer too short")
1 parent ad27acb commit 8aef3fa

File tree

14 files changed

+51
-49
lines changed

14 files changed

+51
-49
lines changed

main/cpp/otf_api/Ir.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ::uint64_t Ir::validValue() const
180180
break;
181181

182182
default:
183-
throw "do not know validValue primitiveType";
183+
throw std::runtime_error("do not know validValue primitiveType [E109]");
184184
break;
185185
}
186186
}
@@ -207,7 +207,7 @@ ::uint64_t Ir::choiceValue() const
207207
break;
208208

209209
default:
210-
throw "do not know choice primitiveType";
210+
throw std::runtime_error("do not know choice primitiveType [E110]");
211211
break;
212212
}
213213
}

main/cpp/otf_api/Listener.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ int Listener::subscribe(OnNext *onNext,
112112
{
113113
char message[1024];
114114

115-
::snprintf(message, sizeof(message)-1, "no IR found for message with templateId=%ld and version=%ld", templateId_, templateVersion_);
115+
::snprintf(message, sizeof(message)-1, "no IR found for message with templateId=%ld and version=%ld [E117]", templateId_, templateVersion_);
116116
onError_->onError(Error(message));
117117
result = -1;
118118
}
119119
}
120120
else if (onError_ != NULL)
121121
{
122-
onError_->onError(Error("template ID and/or version not found in header"));
122+
onError_->onError(Error("template ID and/or version not found in header [E118]"));
123123
result = -1;
124124
}
125125
}

main/cpp/sbe/sbe.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <string.h>
2020
#include <stdint.h>
21+
#include <stdexcept>
2122

2223
/*
2324
* Types used by C++ codec. Might have to be platform specific at some stage.

main/cpp/uk_co_real_logic_sbe_ir_generated/ByteOrderCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ByteOrderCodec
4040
case 255: return NULL_VALUE;
4141
}
4242

43-
throw "unknown value for enum ByteOrderCodec";
43+
throw std::runtime_error("unknown value for enum ByteOrderCodec [E111]");
4444
}
4545
};
4646
}

main/cpp/uk_co_real_logic_sbe_ir_generated/FrameCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class FrameCodec
107107
{
108108
if (SBE_BOUNDS_CHECK_EXPECT((position > bufferLength_), 0))
109109
{
110-
throw "buffer too short";
110+
throw std::runtime_error("buffer too short [E101]");
111111
}
112112
position_ = position;
113113
}

main/cpp/uk_co_real_logic_sbe_ir_generated/MessageHeader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MessageHeader
3232
{
3333
if (SBE_BOUNDS_CHECK_EXPECT((offset > (bufferLength - 8)), 0))
3434
{
35-
throw "buffer too short for flyweight";
35+
throw std::runtime_error("buffer too short for flyweight [E112]");
3636
}
3737
buffer_ = buffer;
3838
offset_ = offset;

main/cpp/uk_co_real_logic_sbe_ir_generated/PresenceCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PresenceCodec
4242
case 255: return NULL_VALUE;
4343
}
4444

45-
throw "unknown value for enum PresenceCodec";
45+
throw std::runtime_error("unknown value for enum PresenceCodec [E113]");
4646
}
4747
};
4848
}

main/cpp/uk_co_real_logic_sbe_ir_generated/PrimitiveTypeCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PrimitiveTypeCodec
6060
case 255: return NULL_VALUE;
6161
}
6262

63-
throw "unknown value for enum PrimitiveTypeCodec";
63+
throw std::runtime_error("unknown value for enum PrimitiveTypeCodec [E114]");
6464
}
6565
};
6666
}

main/cpp/uk_co_real_logic_sbe_ir_generated/SignalCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SignalCodec
7070
case 255: return NULL_VALUE;
7171
}
7272

73-
throw "unknown value for enum SignalCodec";
73+
throw std::runtime_error("unknown value for enum SignalCodec [E115]");
7474
}
7575
};
7676
}

main/cpp/uk_co_real_logic_sbe_ir_generated/TokenCodec.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class TokenCodec
107107
{
108108
if (SBE_BOUNDS_CHECK_EXPECT((position > bufferLength_), 0))
109109
{
110-
throw "buffer too short";
110+
throw std::runtime_error("buffer too short [E102]");
111111
}
112112
position_ = position;
113113
}

0 commit comments

Comments
 (0)