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

Michael Spencer bigcheesegs at gmail.com
Tue Nov 16 10:05:34 PST 2010


On Tue, Nov 16, 2010 at 12:26 PM, Dan Gohman <gohman at apple.com> wrote:
>
> 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.

error_category is the magic that allows the Windows error codes to be
compared with the standard posix error conditions. It also will allow
other libraries to define their own error codes without worrying about
conflicting with the posix errors.

http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html
is a blog series that explains the design decisions behind it.

>>
>> 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

The above is incorrect because KillEvil returns a kill_error, not a
posix error condition (errc). There could be multiple kill_error
values that indicate success, and sys::StrError doesn't know how to
convert any of the values to strings.

- Michael Spencer




More information about the llvm-commits mailing list