in reply to Re: Re5: Error module
in thread Error module

Please help yourself and read up on Perl OO. There are very good books on the matter, one written by our very own Damian Conway. There is also a good section in the Llama book, by our very own Randal Schwartz.

The minimum you'd need to use what I gave you would be to put those lines in a file called SomeError.pm which would be located in a directory called MyErrors. The directory MyErrors should be in the same directory as your Perl script. (You can actually put it anywhere, but it's easiest to just put it there.)

In your Perl script, you put use MyErrors::SomeError; right after the use Error qw(:try); line.

Good luck! If you try this and end up with errors, please post your script and what errors you're getting. That way, we can best help you.

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re7: Error module
by hotshot (Prior) on Aug 19, 2003 at 15:37 UTC
    First of all, thanks for your patience. Secondly, I still can't seem to get this going, I acted exactly as you said, created /usr/local/bin/MyErrors/SomeError.pm with the contents:
    package MyErrors::SomeError; use Error::Simple; @ISA = qw(Error::Simple); 1;
    Then I'v created /usr/local/bin/test.pl with the following contents:
    #!/usr/bin/perl -w use Error qw(:try); use MyErrors::SomeError; try { throw MyErrors::SomeError('throwing SomeError exception'); } catch MyErrors::SomeError with { my $err = shift; print "caught it: $err->{'-text'}\n"; };
    When I run test.pl I get the following error:

    Can't locate MyErrors/SomeError.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0) at /usr/local/bin/test.pl line 4. BEGIN failed--compilation aborted at /usr/local/bin/test.pl line 4.

    It seems that it can't find SomeError.pm, sorry again for the troubling but do you see something wrong here?

    Hotshot
      Yeah, I see a number of things wrong.
      1. Don't code as root. In fact, don't EVER do anything as root unless you absolutely have to. It's dangerous and stupid.
      2. Don't code in /usr/local/bin. In fact, don't code in a bin directory. Ever. Code in some source directory, preferably in a directory under your home directory. I have a directory called 'perl' that I work in.

      Given that you aren't going to fix the above issues before testing this again, I would add use lib qw(/usr/local/bin); above the use MyErrors::SomeError; line. Normally, you run the perl script from the directory it's in. This allows modules that are in that directory (or subdirectories from it) to be auto-included. (This is really nice once you have a proper development environment set up.)

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        I already moved the sorces to my home exactly as you said before I posted the node (of course it screamed the same). Now it gives the same error about Error/Simple.pm.

        P.S: about the root permissions, I can't avoid that since my original script is of course a lot complex and changes Linux internal files

        Hotshot