Skip to content

Commit db56c32

Browse files
committed
Replaced throw with unreachable code logic.
1 parent 3d50939 commit db56c32

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

include/RhythmGameUtilities/Enums/Difficulty.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <string>
44

5+
#include "Enums.h"
6+
57
namespace RhythmGameUtilities
68
{
79

@@ -35,7 +37,7 @@ std::string ToString(Difficulty difficulty)
3537
case Expert:
3638
return "Expert";
3739
default:
38-
throw std::invalid_argument("Unknown Difficulty");
40+
unreachable();
3941
}
4042
}
4143

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <stdexcept>
4+
5+
[[noreturn]] inline void unreachable()
6+
{
7+
#ifdef __GNUC__
8+
__builtin_unreachable();
9+
#elif defined(_MSC_VER)
10+
__assume(0);
11+
#else
12+
std::abort();
13+
#endif
14+
}

include/RhythmGameUtilities/Enums/NamedSection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <string>
44

5+
#include "Enums.h"
6+
57
namespace RhythmGameUtilities
68
{
79

@@ -28,7 +30,7 @@ std::string ToString(NamedSection namedSection)
2830
case Events:
2931
return "Events";
3032
default:
31-
throw std::invalid_argument("Unknown NamedSection");
33+
unreachable();
3234
}
3335
}
3436

include/RhythmGameUtilities/Enums/TypeCode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <string>
44

5+
#include "Enums.h"
6+
57
namespace RhythmGameUtilities
68
{
79

@@ -35,7 +37,7 @@ std::string ToString(TypeCode typeCode)
3537
case EventMarker:
3638
return "E";
3739
default:
38-
throw std::invalid_argument("Unknown TypeCode");
40+
unreachable();
3941
}
4042
}
4143

0 commit comments

Comments
 (0)