This isn't a runtime error (which try/catch work on) but an actual
compilation error...
If you change your code to:
int test = 0;
try {
int blob = 1/test;
} catch {
Response.Write("caught an exception");
}
you'll see the exception caught.
In other words, the Page_Load isn't actually getting executed, simply
compiled...and the compiler is thankfully letting you know there'll always
be an error with your code....always better to have compiler-time errors
than runtime exceptions.
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:up**************@TK2MSFTNGP11.phx.gbl...
Hi All,
The following code throws a "CS0020: Division by constant zero Exception".
I would have expected to see a nice, friendly "caught an exception"
written to the screen.
Can anyone explain?
TIA,
JON
<%@ Page Language="C#" %>
<script runat="server">
public void Page_Load(Object sender, EventArgs e)
{
try
{
int blob = 1/0;
}
catch(Exception ex)
{
Response.Write("caught an exception");
}
}
</script>