Skip to content

Concerning amount of "catch (...)" #4701

Open

Description

@malkia

Describe your environment
I've been reviewing code again, and discovered concerning amount of "catch (...)". I've raised this issue back here -> #4039 (comment) so I wonder if the community is okay with this approach.

From my experience "catch (...)" tends to hide real bad bugs under the rug and makes post-mortem debugging much harder.

Steps to reproduce
N/A

What is the expected behavior?
Have almost no "catch (...)", if needed introduce otel specific exceptions to throw.

What is the actual behavior?
Have too many "catch (...)" which can lead to hidden and hard to find errors.

Additional context
N/A

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Activity

  1. added
    bug
    on Oct 13, 2026
  2. added
    needs-triage
    on Oct 13, 2026
  3. malkia commented on Oct 13, 2026

    @malkia
    Author
    C:\p\open-telemetry\opentelemetry-cpp>git grep -E "catch\W\(\.\.\.\)"
    api/include/opentelemetry/nostd/internal/absl/base/macros.h:#define OTABSL_INTERNAL_CATCH_ANY catch (...)
    examples/etw_threads/main.cc:    catch (...)
    exporters/ostream/src/log_record_exporter.cc:  catch (...)
    exporters/ostream/src/metric_exporter.cc:  catch (...)
    exporters/ostream/src/span_exporter.cc:  catch (...)
    exporters/otlp/src/otlp_file_client.cc:    catch (...)
    sdk/include/opentelemetry/sdk/metrics/observer_result.h:  catch (...)
    sdk/include/opentelemetry/sdk/metrics/observer_result.h:  catch (...)
    sdk/src/configuration/configured_sdk.cc:    catch (...)
    sdk/src/configuration/ryml_document.cc:  catch (...)
    sdk/src/configuration/yaml_configuration_parser.cc:  catch (...)
    sdk/src/logs/logger_provider.cc:  catch (...)
    sdk/src/metrics/export/periodic_exporting_metric_reader.cc:  catch (...)
    sdk/src/metrics/meter_provider.cc:  catch (...)
    sdk/src/trace/tracer.cc:  catch (...)
    sdk/src/trace/tracer_provider.cc:  catch (...)
    
  4. marcalff commented on Oct 13, 2026

    @marcalff
    Member

    @malkia

    What is the expected behavior?
    Have almost no "catch (...)", if needed introduce otel specific exceptions to throw.

    This is not the expected behavior.

    The excepted behavior is that opentelemetry-cpp will not take the application down, no matter how bad it fails internally, including on bad_alloc, and yes, the code is not there yet.

    This is why things like StartSpan() are marked noexcept, these must not fail.

    I do agree with you this can hide other errors that we should know about, see, and then fix.

    Maybe the code should log errors caught (in the SDK and exporters, where we can log to somewhere, but not in the API), but the try/catch is likely to stay.

    Do you have any suggestion about how to proceed ?

  5. marcalff commented on Oct 13, 2026

    @marcalff
    Member
  6. added
    discuss
    triage/accepted
    and removed
    needs-triage
    on Oct 14, 2026
  7. dbarker commented on Oct 14, 2026

    @dbarker
    Member

    This issue was discussed in the SIG meeting today. Where possible in the SDK we should catch explicit exceptions by type and log them. There are cases where an exception catch all block is needed because the exception type is unknown to opentelemetry-cpp. This is the case with callers of user callbacks (e.g. Configurators, Observable instruments, ...).

    The SDK global logger currently allocates memory by constructing a stringstream and may itself throw exceptions. A noexcept diagnostic tool/logger to report exceptions is needed.

  8. malkia commented on Oct 14, 2026

    @malkia
    Author

    Thanks folks! I don't have good suggestions tbh. I've integrated this into some of our internal apps, and my only worry is that we might not get a crashdump where it was needed, or simply have bad data (doesn't have to be opentelemetry's fault, could be like random memory stomp). We are /EHsc users (AFAIK using mix of clang-cl/msvc).

    But I'm glad this was discussed, at least just clarify some of these. (for example bad_alloc makes sense to be handled by configuration for example to gracefully handle this case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdiscusstriage/accepted

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions