From 921e53ecad9d8bc5a692d49807f4f7c2003a971c Mon Sep 17 00:00:00 2001 From: Ankit Bhargava Date: Fri, 31 Jul 2020 01:04:11 -0400 Subject: [PATCH] exception handling --- sdk/include/opentelemetry/sdk/metrics/instrument.h | 4 ++++ sdk/include/opentelemetry/sdk/metrics/sync_instruments.h | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/sdk/include/opentelemetry/sdk/metrics/instrument.h b/sdk/include/opentelemetry/sdk/metrics/instrument.h index 6ba0a30ffd..3a3e525714 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instrument.h +++ b/sdk/include/opentelemetry/sdk/metrics/instrument.h @@ -192,7 +192,11 @@ inline void print_value(std::stringstream &ss, ss << '"'; break; default: +#if __EXCEPTIONS throw std::invalid_argument("Labels must be strings"); +#else + std::terminate(); +#endif break; } }; diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 824eaa48f4..1b2d181118 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -51,7 +51,11 @@ class BoundCounter final : public BoundSynchronousInstrument, public metrics_ this->mu_.lock(); if (value < 0) { +#if __EXCEPTIONS throw std::invalid_argument("Counter instrument updates must be non-negative."); +#else + std::terminate(); +#endif } else { @@ -118,7 +122,11 @@ class Counter final : public SynchronousInstrument, public metrics_api::Count this->mu_.lock(); if (value < 0) { +#if __EXCEPTIONS throw std::invalid_argument("Counter instrument updates must be non-negative."); +#else + std::terminate(); +#endif } else {