[PATCH] D19883: [Support/Error] Add a string conversion method to Error

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 12:42:52 PDT 2016


lhames added a comment.

Hrm. This particular plan sounded better in my head when we were discussing it earlier. My bad.

I like the idea of adding a message() method to ErrorInfoBase so that clients can write something like:

  std::string Msg;
  handle(std::move(Err),
    [&](ErrorInfoBase &E) {
      Msg = E.message();
    });

And I think it'd be useful to wrap all that up in a free function like 'toString', so that you could write:

  std::string Msg = toString(std::move(Err));

However, unless there's a compelling reason not to, I think toString should consume the Error the same way logAllUnhandledErrors does.

The only reason I can think of not to consume the error (but still to log it) is for debugging output:

  auto E = canFail(...);
  DEBUG(OS << "canFail generated an error: " << toString(E) << "\n");
  // ...
  // Actually handle or return E.

If we want to support that idiom we should introduce non-consuming variants of both logAllUnhandled and toString for consistency.


http://reviews.llvm.org/D19883





More information about the llvm-commits mailing list