[llvm-commits] [PATCH] System: Move system_error from KillTheDoctor.

Dan Gohman gohman at apple.com
Tue Nov 16 09:26:17 PST 2010


On Nov 16, 2010, at 12:25 AM, Michael Spencer wrote:

> This is the first step in adding sane error handling support to LLVMSystem.
> 
> The system API's will be shifted over to returning an error_code, and returning
> other return values as out parameters to the function.

What purpose does all the error_category code have here? It looks like,
ultimately, all that's really going on here is an enum and a mapping from
enum values to strings.

> 
> Code that needs to check error conditions will use the errc enum values which
> are the same as the posix_errno defines (EBADF, E2BIG, etc...), and
> are compatable
> with the error codes in WinError.h due to some magic in system_error.
> 
> An example would be:
> 
> if ((error_code ec = KillEvil("Java")) != errc::success) {
>  if (ec == kill_error::too_much_evil)
>    std::terminate();
>  errs() << ":O There was an error! " << ec.message();
> }

How is this better than:

if ((errc ec = KillEvil("Java")) != errc::success) {
 if (ec == kill_error::too_much_evil)
   std::terminate();
 errs() << ":O There was an error! " << sys::StrError(ec))
}

?

Dan





More information about the llvm-commits mailing list