views:

75

answers:

3

Possible Duplicate:
Why are Exceptions not Checked in .NET?

If I remember correctly, Java enforces catching and handling any exceptions a called method may throw. Why doesn't .NET do the same?

+11  A: 

This feature in Java is known as checked exceptions. Anders, creator of C#, did an interview where he explained in detail why they weren't included in C# and consequently VB.Net

I say consequently VB.Net because if neither C# nor the CLR included checked exceptions there was really no reason for VB.Net to include them either. VB was already under a massive transformation from a model which did not include exceptions. Introducing a new exception model which was completely different from the rest of the CLR would have ineffective, created user confusion and lead to more cross language compatibility issues

JaredPar
+3  A: 

I'd suggest reading The Trouble with Checked Exceptions where Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Bill Venners about versionability and scalability issues with checked exceptions.

ho1
+2  A: 

Sometimes you don't want to handle the exception immediately in the method in which it occurs.

Sometimes there isn't anything you can do.

For example, if you are retrieving data from a database, and there is a problem retrieving the data, the Data Access Layer may not be the best place to handle the problem. It might be better to allow the exception to bubble up to the Business Logic Layer or the Presentation Layer, where appropriate information can be displayed to the user.

In .Net, the general approach is to only handle the exception if you can do something about it. And quite often, all you can do is provide useful information to the user.

DOK