473,785 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Exception is Unchecked???

I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a
way to force the C# compiler to catch possible exception?

In Java, all exceptions thrown MUST BE caught, otherwise compiler would give
you error. In C#, is there a way to do that?

Nov 16 '05 #1
16 6592
now you know why I don't use Java.

No, C# will not FORCE you to catch your errors. That's up to you to do, and
it makes sense. You don't always want to catch every error locally. While
it is good practice, it should not be an absolute requirement.

--- Nick

"ChInKPoInt [No MCSD]" <Ch************ *******@gmail.c om> wrote in message
news:G5******** ************@ro gers.com...
I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a way to force the C# compiler to catch possible exception?

In Java, all exceptions thrown MUST BE caught, otherwise compiler would give you error. In C#, is there a way to do that?

Nov 16 '05 #2
Nick Malik <ni*******@hotm ail.nospam.com> wrote:
now you know why I don't use Java.

No, C# will not FORCE you to catch your errors. That's up to you to do, and
it makes sense. You don't always want to catch every error locally. While
it is good practice, it should not be an absolute requirement.


It's not in Java. You don't have to catch every exception (or even
checked exception) locally - you just have to declare which checked
exceptions you can throw.

I believe that checked exceptions of some kind are a good idea; I'm not
sure that Java got it right, and C#/.NET didn't get it right by getting
rid of them entirely. Java feels slightly cumbersome because of them,
and C# sometimes feels like driving without a seatbelt due to the lack
of them. The first language/platform which gets exception handling
really "right" will be interesting...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Nope C# doesn't support checked exceptions. Heres a transcript of Bruce Eckle and Anders Hejlsberg discussing why they are not in C#.

http://www.artima.com/intv/handcuffs.html

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a
way to force the C# compiler to catch possible exception?

In Java, all exceptions thrown MUST BE caught, otherwise compiler would give
you error. In C#, is there a way to do that?
Nov 16 '05 #4

"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:uG******** ******@TK2MSFTN GP10.phx.gbl...
Nope C# doesn't support checked exceptions. Heres a transcript of Bruce
Eckle and Anders Hejlsberg discussing why they are not in C#.

http://www.artima.com/intv/handcuffs.html


I find the "versioning " argument here weak, for two reasons:

The implication is that a method

void M() throws A, B, C

throws precisely A, B and C, and that this handcuffs you in reimplementing
the method. In fact, the method can be changed to throw any subclass of A,
B or C without breaking compatibility. If you're designing a method that
has to remain compatible (one in a widely used library, like the .NET
Framework) A, B and C should be categories of exception like IOException,
not the specific IO exceptions that can be thrown in the first
implementation.

One advantage of checked exceptions is that it allows the documentation to
know which exceptions are thrown. Compare the JDK Javadoc with the .NET API
documentation. You'll see how much better the Javadoc is about showing
which exceptions are thrown and why.
Nov 16 '05 #5
"Mike Schilling" <ms************ *@hotmail.com> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...

"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:uG******** ******@TK2MSFTN GP10.phx.gbl...
Nope C# doesn't support checked exceptions. Heres a transcript of Bruce
Eckle and Anders Hejlsberg discussing why they are not in C#.

http://www.artima.com/intv/handcuffs.html
I find the "versioning " argument here weak, for two reasons:

The implication is that a method

void M() throws A, B, C

throws precisely A, B and C, and that this handcuffs you in reimplementing
the method. In fact, the method can be changed to throw any subclass of
A, B or C without breaking compatibility. If you're designing a method
that has to remain compatible (one in a widely used library, like the .NET
Framework) A, B and C should be categories of exception like IOException,
not the specific IO exceptions that can be thrown in the first
implementation.


How much does it really help you to know that the method throws some kind of
IOException without telling you which ones?

Also, for versioning, consider the case where a method had previously been
written to handle FileStream I/O and therefore had a throws IOException but
now wants to be able to get data from a network as well. The FileStream
parameter is changed to Stream, and the throws clause is changed to include
NetworkExceptio n, and you've got a versioning problem.
One advantage of checked exceptions is that it allows the documentation to
know which exceptions are thrown. Compare the JDK Javadoc with the .NET
API documentation. You'll see how much better the Javadoc is about
showing which exceptions are thrown and why.


Should ease of automatic documentation be a reason to implement a language
feature like this? An <exception> tag in Xml comments in C# solves this
problem without constraining the language.

John Saunders
Nov 16 '05 #6
I believe that checked exceptions of some kind are a good idea; I'm not
sure that Java got it right, and C#/.NET didn't get it right by getting
rid of them entirely. Java feels slightly cumbersome because of them,
and C# sometimes feels like driving without a seatbelt due to the lack
of them. The first language/platform which gets exception handling
really "right" will be interesting...


Yet...somehow I think you'll still find a large percentage of people who
like the java or C# way...

I wonder what right is.
Nov 16 '05 #7

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:uY******** ******@TK2MSFTN GP14.phx.gbl...
"Mike Schilling" <ms************ *@hotmail.com> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...

"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:uG******** ******@TK2MSFTN GP10.phx.gbl...
Nope C# doesn't support checked exceptions. Heres a transcript of Bruce
Eckle and Anders Hejlsberg discussing why they are not in C#.

http://www.artima.com/intv/handcuffs.html
I find the "versioning " argument here weak, for two reasons:

The implication is that a method

void M() throws A, B, C

throws precisely A, B and C, and that this handcuffs you in
reimplementing the method. In fact, the method can be changed to throw
any subclass of A, B or C without breaking compatibility. If you're
designing a method that has to remain compatible (one in a widely used
library, like the .NET Framework) A, B and C should be categories of
exception like IOException, not the specific IO exceptions that can be
thrown in the first implementation.


How much does it really help you to know that the method throws some kind
of IOException without telling you which ones?


Quite a bit.

public void close() throw IOException;

Java reminds you that a close does I/O that can fail (in particular buffer
flushing.) C# doesn't. Any guesses how much C# code handles failures in
Close() ?

Also, for versioning, consider the case where a method had previously been
written to handle FileStream I/O and therefore had a throws IOException
but now wants to be able to get data from a network as well. The
FileStream parameter is changed to Stream, and the throws clause is
changed to include NetworkExceptio n, and you've got a versioning problem.
Not when Network exception is a subclass of IOException, which logically it
will be.
One advantage of checked exceptions is that it allows the documentation
to know which exceptions are thrown. Compare the JDK Javadoc with the
.NET API documentation. You'll see how much better the Javadoc is about
showing which exceptions are thrown and why.


Should ease of automatic documentation be a reason to implement a language
feature like this? An <exception> tag in Xml comments in C# solves this
problem without constraining the language.

But the exception tags don't get put in C# methods, they do get put into the
Java ones.
Nov 16 '05 #8
"Mike Schilling" <ms************ *@hotmail.com> wrote in message
news:eL******** ******@tk2msftn gp13.phx.gbl...

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:uY******** ******@TK2MSFTN GP14.phx.gbl...
"Mike Schilling" <ms************ *@hotmail.com> wrote in message
news:eZ******** ******@TK2MSFTN GP15.phx.gbl...

"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:uG******** ******@TK2MSFTN GP10.phx.gbl...
Nope C# doesn't support checked exceptions. Heres a transcript of Bruce
Eckle and Anders Hejlsberg discussing why they are not in C#.

http://www.artima.com/intv/handcuffs.html

I find the "versioning " argument here weak, for two reasons:

The implication is that a method

void M() throws A, B, C

throws precisely A, B and C, and that this handcuffs you in
reimplementing the method. In fact, the method can be changed to throw
any subclass of A, B or C without breaking compatibility. If you're
designing a method that has to remain compatible (one in a widely used
library, like the .NET Framework) A, B and C should be categories of
exception like IOException, not the specific IO exceptions that can be
thrown in the first implementation.


How much does it really help you to know that the method throws some kind
of IOException without telling you which ones?


Quite a bit.

public void close() throw IOException;

Java reminds you that a close does I/O that can fail (in particular buffer
flushing.) C# doesn't. Any guesses how much C# code handles failures in
Close() ?


All of mine does. ;-)

Look, _anything_ can fail. It does you little good to know that Close() can
throw IOException. How much does that help you over "throws Exception"?

Also, for versioning, consider the case where a method had previously
been written to handle FileStream I/O and therefore had a throws
IOException but now wants to be able to get data from a network as well.
The FileStream parameter is changed to Stream, and the throws clause is
changed to include NetworkExceptio n, and you've got a versioning problem.


Not when Network exception is a subclass of IOException, which logically
it will be.


Why? It isn't in .NET. Don't know about the Java case. If network exceptions
are subclasses of IOException, then tell me what is _not_ a subclass of
IOException (aside from Exception).
One advantage of checked exceptions is that it allows the documentation
to know which exceptions are thrown. Compare the JDK Javadoc with the
.NET API documentation. You'll see how much better the Javadoc is about
showing which exceptions are thrown and why.


Should ease of automatic documentation be a reason to implement a
language feature like this? An <exception> tag in Xml comments in C#
solves this problem without constraining the language.

But the exception tags don't get put in C# methods, they do get put into
the Java ones.


The exception tags get put in by developers who want to document what
exceptions are thrown, and it didn't take a language feature to get that
done. And they're likely to be a lot more specific that "IOExceptio n".

John Saunders
Nov 16 '05 #9

"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:eE******** ******@TK2MSFTN GP14.phx.gbl...
Java reminds you that a close does I/O that can fail (in particular
buffer flushing.) C# doesn't. Any guesses how much C# code handles
failures in Close() ?
All of mine does. ;-)


Good for you. Mine too. A lot doesn't, just in as C, a lot didn't check
the return status from close() or fclose().
Why? It isn't in .NET. Don't know about the Java case. If network
exceptions are subclasses of IOException, then tell me what is _not_ a
subclass of IOException (aside from Exception).

Illegal argument?
Invalid state?
Concurrent modification?
No such class/method/field?
Access not allowed?
etc.


One advantage of checked exceptions is that it allows the documentation
to know which exceptions are thrown. Compare the JDK Javadoc with the
.NET API documentation. You'll see how much better the Javadoc is
about showing which exceptions are thrown and why.

Should ease of automatic documentation be a reason to implement a
language feature like this? An <exception> tag in Xml comments in C#
solves this problem without constraining the language.

But the exception tags don't get put in C# methods, they do get put into
the Java ones.


The exception tags get put in by developers who want to document what
exceptions are thrown, and it didn't take a language feature to get that
done. And they're likely to be a lot more specific that "IOExceptio n".


Then why is the .NET framework documentation so poor in documenting
exceptions compared to the JDK docs?
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
13668
by: Steven Buroff | last post by:
I can't seem to get the @SuppressWarnings("unchecked") to work. Here is my test program. public class Tryit { @SuppressWarnings({"unchecked"}) public <T> T doit(Class<T> clazz){ T val = (T)"xxx"; return val; } }
17
3147
by: Bryan Bullard | last post by:
hi, is there a way to force the user of an object to catch exceptions of specific type? for instance a compile error is issued if exception 'ExeceptionXXX' thrown by method 'ThrowsExceptionXXX' is not caught. thanks,
16
1302
by: ChInKPoInt [No MCSD] | last post by:
I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a way to force the C# compiler to catch possible exception? In Java, all exceptions thrown MUST BE caught, otherwise compiler would give you error. In C#, is there a way to do that?
41
3083
by: Stuart Golodetz | last post by:
Hi all, Just wondering whether there's any reason why exception specifications are enforced at runtime, rather than at compile-time like in Java? (This was prompted by reading an article on GOTW, incidentally.) Is there something about C++ that makes it harder/impossible to check at compile-time? Cheers, Stu
2
2483
by: Spawn666948 | last post by:
Hey, do you guys know how to set the Name Autocorrect to unchecked by default. Name Autocorrect is more trouble than its worth. I know I can go to Tools/General, but, I'd rather have it unchecked by default when I create a blank database. Thanks.
6
1624
by: Bruce | last post by:
I have a reference assembly that I wrote. The assembly can throw exceptions. I am handling these exceptions but, when running my code from VB, VB still insists on setting a breakpoint where the exception is being thrown inside the assembly. Is there anyway to avoid this? If so how?
8
4349
by: pjerald | last post by:
package test; import java.util.ArrayList; public class MyArrayList{ public static void main(String args) { ArrayList al = new ArrayList(); al.add("Jerald"); al.add("PJerald");
1
2471
by: ttamilvanan81 | last post by:
Hai i have using the checkbox in for loop. I need the urgent help from anyone, for example in the loop there is having 5 checkbox if i checked 3 of the ckeckboxes and 2 of the checkboxes are unchecked. I need to get the values for checked checkboxes and unchecked checkboxes. Because if i checked the checkboxes, those values need to be inserted into the database. Those for unchecked checkboxes values need to be deleted from the database. Can...
1
3293
oll3i
by: oll3i | last post by:
E:\ECLIPS~1\ZADANIE3\SRC\EJB>javac -Xlint:unchecked ManageDBBean.java ManageDBBean.java:34: warning: unchecked conversion found : java.util.HashMap required: java.util.Map<java.lang.String,java.lang.String> rowsMap = new HashMap; ^ 1 warning Map<String, String> rowsMap = null;
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.