[ros-kernel] Enhanced error messages

Martin Fuchs martin-fuchs at gmx.net
Mon Jan 5 10:28:28 CET 2004

Hello,

wouldn't you all sometimes wish to see a more descriptive error message
like "File 'c:\path\to\file.txt" could not be found." instead of just that

We can implement this hidden in the OS without breaking any API.
What we need is just to extend CreateFile() and FormatMessage().
If CreateFile() can't find what it was searching for, it calls a new
function SetLastErrorWithInfo(ERROR_FIND_NOT_FOUND, path)
The string is stored like the last error code as per-thread info.
FormatMessage can then look if there is additional information
and include in the formatted message.

Of course this could no only be used for CreateFile().
There are many other functions like CreateProcess(), which
could produce better error messages.

Declaration of the proposed two functions in kernel32:

VOID SetLastErrorWithInfo(DWORD error_code, LPCWSTR info_text);
DWORD GetLastErrorInfo(LPWSTR info_text, LPDWORD buffer_size);

What do you think?

Regards,

Martin