eval { open($DBH, $dbh = DBI->connect('dbi:ODBC:driver=microsoft access driver (*.mdb);dbq=C:\main.mdb')) or die MyFileException->new("Unable to open file - $DBH"); }; if ($@) { # now $@ contains the exception object of type MyFileException # print "raman"; print $@->getErrorMessage(); # where getErrorMessage() is a method in MyFileException class }