priti has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
try { if($session_id eq '') { #create new session $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp/'}) +; } else { #reinitialse with session with session id $session= new CGI::Session(undef, $session_id, {Directory=>'/ +tmp'}); } return $session; } catch IOException with { my $ex = shift; if (!$self->raiseException()) { warn("IOException occurred - " . $ex->getMessage()); return; } }
This is my function to create session and if it fails to find a file it should simply return not to show the user message like "500 internal server error" Please help me on this that how can i efficiently write my exception to deal with this. Regards

Replies are listed 'Best First'.
Re: 500 internal server error !!
by moritz (Cardinal) on Aug 20, 2008 at 10:57 UTC
    Look at your servers error log, it should contain a better description than just "500".

    You can also try to run your script on the command line first and see how it behaves.

      moritz is correct, a simple perl -c <script|module> will find the root cause (syntax error, missing modules) for the majority (but not all) 500 errors.

      -derby
      my error log show /tmp/sess_xxxxxx..... line 30 in filename line 30 is the PHP::Session->new() .It is throwing this error when it is not able to create the session hence 500 internal server error is coming... There is nothing else i can count on i don't know perl is difficult in this case the in-built functions are not that smooth to handle such condition either my knowledge is restricted .... i need some way to check whether session is alive or not??? how one can do this ??? Please help me to come out of it. !!!!
        Maybe you want something like this:
        my $s = eval { PHP::Session->new() }; if ($s) { # I CAN HAZ SESSION } else { # there was an error }
        Is it perl or PHP ??
        []s, HTH, Massa (κς,πμ,πλ)
        Hey, easy with the bangs. Now, what is the "....."? It is the most important part of the error message...
        []s, HTH, Massa (κς,πμ,πλ)
Re: 500 internal server error !!
by massa (Hermit) on Aug 20, 2008 at 12:06 UTC
    Did you remember to use Error::TryCatch?? because if you didn't, you will have a syntax error...
    []s, HTH, Massa (κς,πμ,πλ)
Re: 500 internal server error !!
by pileofrogs (Priest) on Aug 20, 2008 at 17:26 UTC

    Okay, lets step back a step.

    First, does your code run when it's not on a web server? You need to find out if it even compiles first.

    Second, did you upload it in binary or ascii mode? If you uploaded from a Windows box to a unix box in binary mode, you'll get that error.

    Third, read the error logs as mentioned above.

    Fourth, use CGI::Carp with special attention to 'fatalsToBrowser'

    Once you have done all of these things, come back with your error in hand.

Re: 500 internal server error !!
by sasdrtx (Friar) on Aug 20, 2008 at 11:45 UTC
    What kind of Perl has try/catch? This looks like converted Java.

    sas

      Hi,

      It's using Error, which IMHO is not so nice module, even you have to be careful about the ';'.

      Regards,

      fmerges at irc.freenode.net