I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2006-02-24 18:30:23-08 by je44ery
How to Control Exit Values?
Now that I am using Exception::Class to throw exceptions, when my programs halts suddenly due to one of these exceptions, I notice that the exit value is 0, which means that all went OK. I still have a program harness that looks at exit values to perform control operations. How do I set what the exit value will be when my thrown exceptions cause a program halt? Thanks.
Direct Responses: 1851 | Write a response
Posted on 2006-02-24 20:14:04-08 by jdhedden in response to 1849
Re: How to Control Exit Values?
    I notice that the exit value is 0

This doesn't make sense. Exception::Class exits using die(). This results in a non-zero exit status, usually 255. (I tested this to be sure.)

To set your own exit status, you can set a __DIE__ handler and supply exit() with whatever value you want:
$SIG{__DIE__} = sub { print(STDERR @_); exit(99); };
Direct Responses: 1852 | 1870 | Write a response
Posted on 2006-02-24 22:21:32-08 by je44ery in response to 1851
Re: How to Control Exit Values?

Thanks for the signal handling advice, but, yeah, I know it doesn't make any sense to exit 0 when ending the program due to an exception, that's why I posted, but you know what?! Now, I can't recreate it!?

This says that it was all probably an error in my usage/perception. I'll keep hunting for the situations in which I had thought I was getting exit values of 0 during an exception, but for the moment, I have tried 3 different situations, and none are now exiting with a value of 0! I'm glad I was mistaken, but I'm also now mystified.

Direct Responses: Write a response
Posted on 2006-02-28 19:14:26-08 by je44ery in response to 1851
Re: How to Control Exit Values?
I knew I wasn't hallucinating!
Missing file during compare Results were: Trace begun at My/Class/Compare.pm line 133 My::Class::Compare::_compare('My::Class::Compare=SCALAR(0x3036f5a8)', 'ARRAY(0x302a79a4)', 'ARRAY(0 +x3068ae40)') called at My/Class/Compare.pm line 173 My::Class::Compare::run('My::Class::Compare=SCALAR(0x3036f5a8)') called at do_something.pl line 66 root@mybox:/home/me # echo $? 0
I have Exception::Class::Base->Trace(1); so that is why the full trace appears. I also know it was my Exception that was called because of the first 2 lines. Those are my own error messages from my overridden full_message() method of the exception class. So here is an example of an exception being thrown, and the exit value being 0.

Names have been changed to protect the innocent.
Direct Responses: 1946 | Write a response
Posted on 2006-03-14 17:48:12-08 by je44ery in response to 1870
Re: How to Control Exit Values?

OK, this follow-up to to show that my exit-0-on-exception was not a problem with Exception::Class nor die. I was getting exit values of 0 for 3 different reasons. I hunted them all down, and it was all my fault.

1. This one is embarassing. When I was testing my code, firing from the hip on the command line, you might say, I did this:

my_prog.pl 2>&1 | tee /tmp/my_prog.out

Of course, then I did echo $? I was getting the return value of tee! Doh!

2. I was using rsh on some commands. rsh does NOT return the exit value of the command it ran, but it returns 0 if it was able to run a command at all, even if that command returned non-zero. You must come up with a workaround to acquire the exit value of an rshed command.

3. This one actually involved my Perl code. In some scripts, I was using END{} subroutines, and I was not handing off the bad exit value. So the exit value of my perl progran during an exception was 0 if my last command in the END{} sub was good.

Direct Responses: Write a response