debugging (stepping thru in debugger) within a try block

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


i have recently started using the exception handling using
try ... catch ... otherwise ... finally.

those are great OO concepts.

when i use perl debugger on code using the above try... catch etc,
i am unable to step thru the code in those try ... catch blocks.

is there any way to step thru those blocks of code which seem to be
getting executed as a single unit (like eval i think)?

thanks for your help,

Re: debugging (stepping thru in debugger) within a try block

Quoted text here. Click to load it

They also don't exist in Perl, at least not under those names.  Are
you using a module which provides functions with those names, such as
Exception::Class::TryCatch?  If so, you really need to tell us,
because CPAN is huge, and nobody knows offhand which modules you're
using if you don't tell us.

Also, have you read the Posting Guidelines?  They're not meant to
cause you pain, but if you read them, and follow them, then you will
make it very easy for us to help you.  Specifically, one of the
guidelines is that you should post the smallest complete program
possible that exhibits your problem.  Once you get it running (I think
it should only be 10 or 12 lines, at most), cut and paste it here-- do
NOT retype it!  Every single time I see somebody retype their code,
they always make a mistake.  When you cut and paste, if there is a
mistake, it's a real one, not a mistake introduced by typos.

Quoted text here. Click to load it

You need to tell us what these try/catch blocks are, and how you get
them.  Perl does not have them by default, so it is your job to tell
us where they came from.


Re: debugging (stepping thru in debugger) within a try block

Quoted text here. Click to load it

Oops, my mistake, sorry.  I thought I was in c.l.p.misc, not .modules.
Anyway, if the OP were to read the Posting Guidelines in c.l.p.misc,
they would help him ask helpful questions. :)


Re: debugging (stepping thru in debugger) within a try block

hi eric,

no problem. actually the guidelines you noted are good in general and
going to follow for my further posts.

writing sample program gave me the solution :)

looks like my problem was that my code was using 'try' as defined
by std perl module. looks like this module would try to
the entire 'try block' as some anonymous code segment and hence won't
you to step into the code.

looks like perl 5.8.6 does understand try natively and if you use it,
debugger has
no problem stepping into the try blocks.

hopefully the program listing i have answers your other quesions as to
which cpan module i am using etc.


# note that in the program below you will be able to step into the
#  try blocks if you comment out 'use Error qw(:try)'.

#!/usr/cisco/bin/perl5.8 -w

use Error qw(:try);
use Exception::Class (
    SubExc => {},

sub main {
    try {
        my $v1 = 'v1'; # you can't break here if you are using
    } catch Exception::Class::Base with {
    } otherwise {

sub sub2 {
    try {
        my $v1 = 'abc';
        throw SubExc "exception while performing sub processing";


Re: debugging (stepping thru in debugger) within a try block

Quoted text here. Click to load it

That's usually the case, which is why the advice to do so in the first
place. :)

Quoted text here. Click to load it

I have never used that module.  I'm not sure I even knew it existed.
I may have to play with it a bit, just for giggles.


Site Timeline