Berger, Daniel wrote:> Heya all,
>
> I don''t think I''ve been paying attention. When a Windows
API function
> fails, I could have been doing this:
>
> raise SystemCallError(GetLastError())
Whoops, that should have been SystemCallError.new(GetLastError())
> Instead of this:
>
> # Where ''Error'' is nested under the current class.
> raise Error, get_last_error
>
> I''m not sure how big of a deal this is in practice, however, or if
it''s
> even preferred for our purposes.
A bit more research indicates that the error messages don''t always
match
up if you do this. For example, if you do:
unless RemoveDirectory(bogus)
raise SystemCallError.new(GetLastError()) # GetLastError returns 3
end
The result is Errno::ESRCH (errno 3), whereas Ruby would raise
Errno::ENOENT, which is errno 2. Looking at win32.c I now see why -
they''ve got certain errors specifically mapped to certain codes. Take a
look at the errmap struct.
Regards,
Dan