The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

<!--  Presentation generated by Internet Assistant for Microsoft PowerPoint 97 -->

<HTML>
<HEAD>

<meta name="GENERATOR" content="Microsoft Internet Assistant for Microsoft PowerPoint 97">
 <TITLE>More Custom Error Handling</TITLE> 
</HEAD>

<BODY     >

<CENTER>
<TABLE WIDTH=100%> 
     <TR> <TD WIDTH=100% ALIGN=CENTER>
         <A HREF="sld001.htm">First</A>&nbsp;&nbsp;
         <A HREF="sld044.htm">Previous</A>&nbsp;&nbsp;
         <A HREF="sld046.htm">Next</A>&nbsp;&nbsp;
         <A HREF="sld093.htm">Last</A>&nbsp;&nbsp;
&nbsp;&nbsp;         <A HREF="index.htm">Index</A>&nbsp;&nbsp;
         <A HREF="dbi.perl.org">Home</A>&nbsp;&nbsp;
         <A HREF="tsld045.htm">Text</A>&nbsp;&nbsp;
     </TD> </TR>
     <TR> <TD WIDTH=100% ALIGN=CENTER>
         <IMG SRC="img045.gif" usemap="#Objmap" WIDTH=800 HEIGHT=600 BORDER=0>
     </TD> </TR>
</TABLE>
<P>Slide 45 of 93</P>
</CENTER>
<!-- <UL>
<H2>More Custom Error Handling</H2>
</UL></P>
<P><UL>
<LI><H2>It is also possible for HandleError to hide an error, to a limited degree
</H2>
<UL>
<LI>use set_err() to reset $DBI::err and $DBI::errstr
<LI>alter the return value of the failed method
<LI>
</UL>$h-&#062{HandleError} = sub {
<BR>    my ($errmsg, $h) = @_;
<BR>    return 0 unless $errmsg =~ /^\S+ fetchrow_arrayref failed:/;
<BR>    return 0 unless $h-&#062err == 1234; # the error to 'hide'
<BR>    $h-&#062set_err(0,"");	# turn off the error
<BR>    $_[2] = [ ... ];	# supply alternative return value by altering parameter
<BR>    return 1;
<BR>};
<LI>
</UL><UL>
<LI><H2>Only works for methods which return a single value and is hard to make reliable (avoiding infinite loops, for example) and so isn't recommended for general use!
</H2>
<UL>
<LI>If you find a good use for it then please let me know.
</UL></UL><UL>
<H2>_</H2>
</UL></P>
<P>  -->
</Body>
</HTML>