Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/GSL.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/gsl/gsl_util8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util
index d1f7f33..bc65923 100644
--- a/include/gsl/gsl_util
+++ b/include/gsl/gsl_util
@@ -96,6 +96,10 @@ constexpr T narrow_cast(U&& u) noexcept
return static_cast<T>(std::forward<U>(u));
}
+struct narrowing_error : public std::exception
+{
+};
+
namespace details
{
template <class T, class U>
@@ -115,9 +119,9 @@ constexpr
T narrow(U u) noexcept(false)
{
T t = narrow_cast<T>(u);
- if (static_cast<U>(t) != u) gsl::details::terminate();
+ if (static_cast<U>(t) != u) throw narrowing_error{};
if (!details::is_same_signedness<T, U>::value && ((t < T{}) != (u < U{})))
- gsl::details::terminate();
+ throw narrowing_error{};
return t;
}