Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Source/LuaBridge/detail/Expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -976,19 +976,20 @@ template <class E>
class BadExpectedAccess;

template <>
class BadExpectedAccess<void> : public std::exception
class BadExpectedAccess<void> : public std::runtime_error
{
public:
explicit BadExpectedAccess() noexcept
explicit BadExpectedAccess(const std::string& message) noexcept
: std::runtime_error(message)
{
}
};
template <class E>
class BadExpectedAccess : public BadExpectedAccess<void>
{
public:
explicit BadExpectedAccess(E error) noexcept(std::is_nothrow_constructible_v<E, E&&>)
: error_(std::move(error))
explicit BadExpectedAccess(E error, const std::string& message) noexcept(std::is_nothrow_constructible_v<E, E&&>)
: BadExpectedAccess<void>(message), error_(std::move(error))
{
}

Expand Down Expand Up @@ -1265,7 +1266,7 @@ class Expected : public detail::ExpectedBase<T, E, std::is_copy_constructible_v<
{
#if LUABRIDGE_HAS_EXCEPTIONS
if (!hasValue())
throw BadExpectedAccess<E>(error());
throw BadExpectedAccess<E>(error(), error().message());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E is a templated class and can be anything. Here you are assuming is has a "message" method. We should solve it differently, using a detector on the E::message method (or eventually a to_string(E)) free function on the type if defined, inside the BadExpectedAccess constructor.

#endif

return base_type::value();
Expand All @@ -1275,7 +1276,7 @@ class Expected : public detail::ExpectedBase<T, E, std::is_copy_constructible_v<
{
#if LUABRIDGE_HAS_EXCEPTIONS
if (!hasValue())
throw BadExpectedAccess<E>(error());
throw BadExpectedAccess<E>(error(), error().message());
#endif

return base_type::value();
Expand All @@ -1285,7 +1286,7 @@ class Expected : public detail::ExpectedBase<T, E, std::is_copy_constructible_v<
{
#if LUABRIDGE_HAS_EXCEPTIONS
if (!hasValue())
throw BadExpectedAccess<E>(error());
throw BadExpectedAccess<E>(error(), error().message());
#endif

return std::move(base_type::value());
Expand All @@ -1295,7 +1296,7 @@ class Expected : public detail::ExpectedBase<T, E, std::is_copy_constructible_v<
{
#if LUABRIDGE_HAS_EXCEPTIONS
if (!hasValue())
throw BadExpectedAccess<E>(error());
throw BadExpectedAccess<E>(error(), error().message());
#endif
return std::move(base_type::value());
}
Expand Down