Re: Try-catch not working - why does this throw an Exception?
From: Karl Seguin (_at_)
Date: 10/25/04
- Next message: Bob Rock: "Why Invoke() can be called on .NET framework delegates and not on my own????"
- Previous message: Jon Maz: "Re: Try-catch not working - why does this throw an Exception?"
- In reply to: Jon Maz: "Try-catch not working - why does this throw an Exception?"
- Next in thread: Jon Maz: "Re: Try-catch not working - why does this throw an Exception?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 25 Oct 2004 11:40:54 -0400
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" <jonmaz@surfeuNOSPAM.de> wrote in message news:upb7DZquEHA.1288@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> > > >
- Next message: Bob Rock: "Why Invoke() can be called on .NET framework delegates and not on my own????"
- Previous message: Jon Maz: "Re: Try-catch not working - why does this throw an Exception?"
- In reply to: Jon Maz: "Try-catch not working - why does this throw an Exception?"
- Next in thread: Jon Maz: "Re: Try-catch not working - why does this throw an Exception?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|