Home > Archive > PerlTk > May 2007 > Where do the errors go?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Where do the errors go?
|
|
| Jim Ford 2007-04-06, 8:01 am |
| Where do the errors go when running a Perl Tk script?
I find it most frustrating when running a script and nothing happens -
no errors on the console or anywhere I can find. I usually resort to
'salting' the script with print statements to get an idea of where it
stops. Is there another way, other than running the script with the
debugger?
Jim Ford
| |
| zentara 2007-04-06, 7:03 pm |
| On Fri, 06 Apr 2007 10:36:09 GMT, Jim Ford
<jaford@watford53.freeserve.co.uk> wrote:
>Where do the errors go when running a Perl Tk script?
>
>I find it most frustrating when running a script and nothing happens -
>no errors on the console or anywhere I can find. I usually resort to
>'salting' the script with print statements to get an idea of where it
>stops. Is there another way, other than running the script with the
>debugger?
>
>Jim Ford
Try this:
#!/usr/bin/perl -w
use strict;
use Tk;
require Tk::ErrorDialog;
my $mw = new MainWindow();
#generate an error by calling to subroutine
open_file();
MainLoop;
sub open_file{
#notice the die statement
#we have 2 flavors: a message going to STDOUT and an error
#dialog being displayed
open(FILE,"duh.txt") or die "File error: $!",$mw->Tk::Error("Can't open
file\n$!\n");
my @file = <FILE>;
close FILE;
}
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Jim Ford 2007-04-06, 7:03 pm |
| zentara wrote:
> On Fri, 06 Apr 2007 10:36:09 GMT, Jim Ford
> <jaford@watford53.freeserve.co.uk> wrote:
>
>
> Try this:
>
> #!/usr/bin/perl -w
> use strict;
> use Tk;
> require Tk::ErrorDialog;
>
> my $mw = new MainWindow();
> #generate an error by calling to subroutine
> open_file();
> MainLoop;
>
> sub open_file{
> #notice the die statement
> #we have 2 flavors: a message going to STDOUT and an error
> #dialog being displayed
> open(FILE,"duh.txt") or die "File error: $!",$mw->Tk::Error("Can't open
> file\n$!\n");
> my @file = <FILE>;
> close FILE;
> }
>
>
> __END__
>
Thanks - I'll give it a try when I'm back on the machine I'm running Perl.
Jim Ford
| |
| zentara 2007-04-07, 8:03 am |
| On Fri, 06 Apr 2007 15:55:07 GMT, Jim Ford
<jaford@watford53.freeserve.co.uk> wrote:
[color=darkred]
[color=darkred]
>Thanks - I'll give it a try when I'm back on the machine I'm running Perl.
>
>Jim Ford
That was a specialized example, it's actually much simpler.
#!/usr/bin/perl -w
use strict;
use Tk;
require Tk::ErrorDialog;
my $mw = new MainWindow();
#generate an error by calling to subroutine
$mw->Button(-text=>'test',-command =>\&testit)->pack();
MainLoop;
sub testit{
my $y = 1;
my $x = 0;
my $z = $y/$x;
}
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
|
|
|
|
|
|
|
|
|