Thanks Rob, that's exactly what I needed! As usual, you were right on the
money--even with "completely untested" code. :)
-Rob
-----Original Message-----
From: ro...@th... [mailto:ro...@th...] On Behalf Of
Robert May
Sent: Tuesday, July 03, 2007 12:48 PM
To: Perl Rob
Cc: Win32 GUI Users Mailing List
Subject: Re: [perl-win32-gui-users] How to catch unwanted Win32::Printer
errors
On 03/07/07, Perl Rob <pe...@co...> wrote:
>
> When I run my code to print an image file, the standard "Print" dialog
> appears as expected, and my file is printed without problems if I click
> "OK". However, if I click "Cancel" on the dialog, Win32::Printer opens a
> dialog box with a cryptic error (about a printer object not being created)
> that my users will not understand and that I don't want them to see. Any
> ideas on how I can suppress (or take control of) this behavior from
> Win32::Printer? I expect that I need to use an eval block, but I'm not
sure
> how to use eval (getting all sorts of syntax errors). Here's my code:
>
> my $dc = new Win32::Printer
> (
> papersize => LETTER,
> dialog => NOSELECTION,
> description => ' Coloring Page(s)',
> unit => 'mm'
> );
Rob,
I've never used Win32::Print, but did take a quick ppek at the code.
I think you can do something like this (completely untested):
my $dc = eval { Win32::Printer->new( ... YOUR OPTIONS HERE ... ); };
if ($@) { # There was a die() in the eval
if($^E != 1223) { # Win32::Printer does SetLastError(ERROR_CANCELLED)
# if user presses cancel
die $@;
}
else {
# user cancelled, do something
}
}
Regards,
Rob.
|