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 {