Generally speaking, when Perl encounters an error, it sets the error variables ($!) to both the error number and the textual error message. This enables the script to determine the nature of a Perl-generated error. The $! variable usually reports system errors. The $^E variable reports Win32 errors. However, most modules and extensions generally do not touch this variable.
Instead, they use their own way of error reporting, which makes it difficult for a coder to discover error information because the technique differs from extension to extension.
The Win32 extension defines two very important error functions: the GetLastError() and FormatMessage().
The Win32::GetLastError() function returns an error code ...