I'm using Perl CGI and Apache::Session in my web application.
When setting up an Apache::Session using tie like this:
tie %session, 'Apache::Session::MySQL', $id, {
    DataSource => 'dbi:mysql:apache_session', 
    UserName   => 'root',         
    Password   => '',           
    LockDataSource => 'dbi:mysql:apache_session',
    LockUserName   => 'root',
    LockPassword   => ''
};
How do I catch the error that occurs when $id is not a valid session in the database? I need to create a new session ID instead of having the application die with a 500 http error.
This situation occurs when the user has an outdated cookie with a session ID that has been removed from the database.
                        
If the
$idvariable has a value ofundef, Apache::Session creates a new session ID. Now if$idis defined but does not appoint a valid session here then an exception will be thrown.One way you could do this is to wrap
tiein anevalblock.If an exception is thrown, you can check to see whether the message indicates that the session isn't valid.