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? 16 1292
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?
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
"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.
"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 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.
"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.
"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
"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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
}
}
|
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,
|
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?
|
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
|
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.
| |
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?
|
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");
|
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...
|
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;
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |