Re: How to prevent compiling when an exception has not been handeled
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 08 Aug 2007 18:46:59 -0700
shahoo wrote:
Hi,
As you know in Java, when a method is able to throw an exception the
programmer has to handle the exception otherwise the program will not
compile.
Is there anyway to do so in C#. I mean generate an error message for
each unhandled exception?
No. C# doesn't provide a way to advertise to the compiler which exceptions it could throw, so there's also no way for it to require that calling methods always catch exceptions that could be thrown.
Not having done any Java programming myself, I had never heard of that feature until someone else asked the same question a while back. I still have mixed feelings regarding whether I'd want to use that sort of requirement. On the one hand, it seems like a good idea with respect to making sure you always know what kind of exceptions you might need to handle. On the other hand, it sounds like it could lead to a lot of busy work, as you repeatedly bubble up possible exceptions. :)
Pete
.
- Follow-Ups:
- Re: How to prevent compiling when an exception has not been handeled
- From: Samuel R . Neff
- Re: How to prevent compiling when an exception has not been handeled
- From: Jon Skeet [C# MVP]
- Re: How to prevent compiling when an exception has not been handeled
- References:
- Prev by Date: Re: How to prevent compiling when an exception has not been handeled
- Next by Date: Clarifying the Relationship Between Delegates and Events
- Previous by thread: Re: How to prevent compiling when an exception has not been handeled
- Next by thread: Re: How to prevent compiling when an exception has not been handeled
- Index(es):
Relevant Pages
|