LCOV - code coverage report
Current view: top level - common/include/scipp/common - except.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 2 0.0 %
Date: 2024-04-28 01:25:40 Functions: 0 1 0.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: BSD-3-Clause
       2             : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
       3             : /// @file
       4             : /// @author Simon Heybrock
       5             : #pragma once
       6             : 
       7             : #include <initializer_list>
       8             : #include <stdexcept>
       9             : #include <string>
      10             : 
      11             : namespace scipp::except {
      12             : 
      13             : template <class T> struct Error : public std::runtime_error {
      14             :   using std::runtime_error::runtime_error;
      15             :   template <class T2>
      16             :   Error(const T2 &object, const std::string &message)
      17             :       : std::runtime_error(to_string(object) + message) {}
      18             : };
      19             : 
      20             : template <class Expected, class Actual>
      21           0 : [[noreturn]] void throw_mismatch_error(const Expected &expected,
      22             :                                        const Actual &actual,
      23             :                                        const std::string &optional_message) {
      24           0 :   throw Error<std::decay_t<Expected>>("Expected  " + to_string(expected) +
      25             :                                       " to be equal to " + to_string(actual) +
      26             :                                       '.' + optional_message);
      27             : }
      28             : 
      29             : template <class Expected, class Actual>
      30             : [[noreturn]] void
      31             : throw_mismatch_error(const Expected &expected,
      32             :                      const std::initializer_list<Actual> actual) {
      33             :   throw Error<std::decay_t<Expected>>("Expected " + to_string(expected) +
      34             :                                       " to be equal to one of " +
      35             :                                       to_string(actual));
      36             : }
      37             : } // namespace scipp::except

Generated by: LCOV version 1.14