Error code enums

Let’s replace err with something likely in many people’s code, a strongly typed enum:


  struct udt
  {
    int a{0};
    explicit udt(int _a)
        : a(_a)
    {
    }
    udt() = default;
    int operator*() const { return a; }
  };
  enum class err
  {
    success,   // REMEMBER it is best practice to always put "success"
    failure1,  // with value 0 as your first item in any error code
    failure2   // enum, even if you never use it.
  };
  result<udt, err> res(err::failure1);

  // What happens here? What exception type is thrown?
  try
  {
    std::cout << *res.value() << std::endl;
  }
  catch(const std::exception &e)
  {
    std::cerr << "Exception thrown was " << e.what() << std::endl;
  }
  
View this code on Github