my $rc = $sth->execute() or die "MYERROR: Can't execute statement: $DBI::errstr"; #### /* define the message, drop it first just in case we are actually changing it. */ sp_dropmessage 9999000 go sp_addmessage 9999000, "Throwing error as @throw='%1!'" go /* define the stored proc, drop it first just in case we are actually changing it. */ drop proc check_error_return go create proc check_error_return @throw numeric(1)=null as if (@throw is null) begin select name from sysobjects where type='P' end else begin raiserror 9999000,@throw return -1 end go #### use strict; use warnings; use DESD::DBI_Utils qw(open_db_connection); $|++; use constant DATABASE => 'SOMEDB'; print "Establishing connection to DB ".DATABASE()."\n"; my $dbh = open_db_connection( 'me', 'password', server => 'MYSERVER', database => DATABASE ); for my $raiserror (0,1) { for my $printerror (0,1) { $dbh->{RaiseError}=$raiserror; $dbh->{PrintError}=$printerror; for my $val qw(1 null) { eval { print "RaiseError=$raiserror PrintError=$printerror Value=$val\n"; my $sth=$dbh->prepare("exec check_error_return \@throw=$val") or die "MYERROR: Can't prepare statement: $DBI::errstr"; my $rc = $sth->execute() or die "MYERROR: Can't execute statement: $DBI::errstr"; print "Got:"; my $ret; while (($ret) = $sth->fetchrow_array) { print "$ret\t"; } print "\n"; # check for problems which may have terminated the fetch early die "MYERROR:".$sth->errstr if $sth->err; }; if ($@) { if ($@=~/MYERROR/) { print "Got an inline error:\n$@"; } else { print "Got an exception:\n$@"; } } else { print "No error\n"; } } } } #### Establishing connection to DB SOMEDB RaiseError=0 PrintError=0 Value=1 Got:-1 No error RaiseError=0 PrintError=0 Value=null Got:check_error_return No error RaiseError=0 PrintError=1 Value=1 DBD::Sybase::st execute failed: Server message number=9999000 severity=16 state=1 line=7 procedure=check_error_return text=Throwing error as @throw='1' at D:\Development\rating\throw_error.pl line 43. Got:-1 No error RaiseError=0 PrintError=1 Value=null Got:check_error_return No error RaiseError=1 PrintError=0 Value=1 Got an exception: DBD::Sybase::st execute failed: Server message number=9999000 severity=16 state=1 line=7 procedure=check_error_return text=Throwing error as @throw='1' at D:\Development\rating\throw_error.pl line 43. RaiseError=1 PrintError=0 Value=null Got:check_error_return No error RaiseError=1 PrintError=1 Value=1 DBD::Sybase::st execute failed: Server message number=9999000 severity=16 state=1 line=7 procedure=check_error_return text=Throwing error as @throw='1' at D:\Development\rating\throw_error.pl line 43. Got an exception: DBD::Sybase::st execute failed: Server message number=9999000 severity=16 state=1 line=7 procedure=check_error_return text=Throwing error as @throw='1' at D:\Development\rating\throw_error.pl line 43. RaiseError=1 PrintError=1 Value=null Got:check_error_return No error