Error Handling

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().

GetLastError() Function

The Win32::GetLastError() function returns an error code ...

Get Win32 Perl Programming: The Standard Extensions, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.