[Mono-list] Exception handling

Ferguson, Neale Neale.Ferguson@SoftwareAG-USA.com
Wed, 14 Apr 2004 07:42:01 -0600


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C42226.439C3B00
Content-Type: text/plain;
	charset="iso-8859-1"

I have the following piece of code:
 
class Tests {
 
        static int Main () {
                return TestDriver.RunTests (typeof (Tests));
        }
 
        static int test_0_byte_cast () {
                int a;
                long l;
                byte b = 0;
                bool failed;
 
                try {
                        double d = 256;
                        failed = true;
                        checked {
                                b = (byte)d;
                        }
                } catch (OverflowException) {
                        failed = false;
                }
                if (failed)
                        return 8;
                if (b != 255)
                        return -8;
 

                return 0;
        }
}

When I run it I get an unhandled exception raised. Tracing shows me that the
call comes from:
 
static gint64
mono_fconv_ovf_i8 (double v)
{
        gint64 res;
 
        MONO_ARCH_SAVE_REGS;
 
        res = (gint64)v;
 
        if (isnan(v) || truncl (v) != res) {
                mono_raise_exception (mono_get_exception_overflow ());
        }
        return res;
}

Which is called by the test code. Now, the method->save_lmf flag for the
code is not set so that the lmf stuff has not been setup and thus the
exception handling code can't locate the JIT code involved and will
therefore treat this as an unhandled exception. Why wouldn't the save_lmf
flag be set? I don't see my example calling and icall_wrapper type routine.

Neale Ferguson 
R&D Fellow 
Software AG 

 

------_=_NextPart_001_01C42226.439C3B00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">


<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D454242313-14042004><FONT face=3DArial size=3D2>I =
have the following=20
piece of code:</FONT></SPAN></DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New" =
size=3D2>class Tests=20
{</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static int Main ()=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
return TestDriver.RunTests (typeof=20
(Tests));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static int =
test_0_byte_cast ()=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
int=20
a;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
long=20
l;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
byte b =3D=20
0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
bool failed;</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New"=20
size=3D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bsp;=20
} catch (OverflowException)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

failed =3D=20
false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
if=20
(failed)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
return=20
8;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
if (b !=3D=20
255)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
return -8;</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV><SPAN =
class=3D454242313-14042004>
<DIV><BR><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;=20
return 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}<BR>}<BR></FONT></DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3DArial size=3D2>When =
I run it I get=20
an unhandled exception raised. Tracing shows me that the call comes=20
from:</FONT></SPAN></DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New" =
size=3D2>static=20
gint64<BR>mono_fconv_ovf_i8 (double=20
v)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gint64=20
res;</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
MONO_ARCH_SAVE_REGS;</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res =3D=20
(gint64)v;</FONT></SPAN></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3D"Courier New"=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (isnan(v) || =
truncl (v) !=3D=20
res)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
mono_raise_exception (mono_get_exception_overflow=20
());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
res;<BR>}<BR></FONT></SPAN></DIV>
<DIV><SPAN class=3D454242313-14042004><FONT face=3DArial size=3D2>Which =
is called by=20
the test code. Now, the method-&gt;save_lmf flag for the code is not =
set so that=20
the lmf stuff has not been setup and thus the exception handling code =
can't=20
locate the JIT code involved and will therefore&nbsp;treat this as=20
an&nbsp;unhandled exception. Why wouldn't the save_lmf flag be set? I =
don't see=20
my&nbsp;example calling and icall_wrapper type=20
routine.</DIV></FONT></SPAN></SPAN>
<P><FONT face=3D"Monotype Corsiva">Neale Ferguson</FONT> <BR><FONT =
face=3DArial=20
size=3D2>R&amp;D Fellow</FONT> <BR><FONT face=3DArial size=3D2>Software =
AG</FONT> </P>
<DIV>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C42226.439C3B00--