473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

throws keyword

does c# provide an alternative to the throws keyword in javA?so that my
client developer will strictly implement the exceptions that my methods may
throw?
thanks in advance
Nov 23 '07 #1
6 1917
Just for discussion, would anyone like this functionality added?

I agree there are issues with Java's checked exception, as posed by
this typical code block:

try{ Thread.sleep(3000);}
catch (InterruptedException ie) { ??? Not a bloody thing I can do
about it ???}

If it's going to happen, and I can't do anything about it, then why am
I FORCED to catch it.

However, I wouldn't mind at all if I was warned about checked
exceptions.

WARNING: Potential Exception "UserIsAMoronException" not caught in
line 205.

Then I would at least be reminded of the possibility. I'm a smart
guy, but I can't memorize the entire C# API and all exceptions that
might be thrown. Warnings would be useful.
Nov 23 '07 #2
On Nov 23, 3:52 pm, chris <chris.cudm...@gmail.comwrote:
Just for discussion, would anyone like this functionality added?
I used to be in favour of checked exceptions. I've since learned to
live without the seatbelt, as it were.

I think they were a useful experiment, but one which ultimately was
unsuccessful. I would like to see *something* in their stead, but I'm
not sure what yet.

Jon
Nov 23 '07 #3
Lew
chris wrote:
try{ Thread.sleep(3000);}
catch (InterruptedException ie) { ??? Not a bloody thing I can do
about it ???}
Wrong. There are many bloody things you can do about that in Java. You just
don't know them yet.

In fact, handling InterruptedException in Java is one of its fundamental
idioms, and it helps a lot with concurrent programming if you know what to do
with it. Admittedly, it is a rather low-level construct.

This is not to argue for or against using checked exceptions in C#, only to
state as a point of fact that InterruptedException in Java is not only readily
managed, it's a common idiom to do so.

--
Lew
Nov 23 '07 #4
Emre DİNÇER wrote:
does c# provide an alternative to the throws keyword in javA?so that my
client developer will strictly implement the exceptions that my methods may
throw?
..NET chose to make all exceptions unchecked.

http://www.artima.com/intv/handcuffs.html gives some
insight in why.

Arne
Nov 26 '07 #5
chris wrote:
Just for discussion, would anyone like this functionality added?

I agree there are issues with Java's checked exception, as posed by
this typical code block:

try{ Thread.sleep(3000);}
catch (InterruptedException ie) { ??? Not a bloody thing I can do
about it ???}

If it's going to happen, and I can't do anything about it, then why am
I FORCED to catch it.
In 25 lines demo code that exception is usually ignored, because
the programmer know that it will never happen.

In a real program it would not be unusual to expect the thread
to do something as a consequence of it being interrupted by
some code in the parent thread.
However, I wouldn't mind at all if I was warned about checked
exceptions.

WARNING: Potential Exception "UserIsAMoronException" not caught in
line 205.

Then I would at least be reminded of the possibility. I'm a smart
guy, but I can't memorize the entire C# API and all exceptions that
might be thrown. Warnings would be useful.
A lot of sites (maybe even most sites) has a no tolerance policy
about warnings.

Meaning that that even a warning would force people to catch.

Arne
Nov 26 '07 #6
On Nov 23, 12:19 pm, Lew <l...@lewscanon.comwrote:
chris wrote:
try{ Thread.sleep(3000);}
catch (InterruptedException ie) { ??? Not a bloody thing I can do
about it ???}

Wrong. There are many bloody things you can do about that in Java. You just
don't know them yet.
In the example given, which I admit was rather simplistic, there
really isn't anything you can do about it.

You are right in that there are several things I MUST do if a
MEANINGFUL thread is interrupted (save state, try and recover, exit
gracefully and try again), but not in the STATIC sleep() method other
than a) ignore b) try again (If I really must sleep).
Short of virtual machine errors, I can't think of anything that would
cause Thread.sleep() to throw an exception.
Perhaps that would have been better served by throwing an error rather
than an exception.

Dec 6 '07 #7

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

Similar topics

3
by: Sébastien Ros | last post by:
During the process of an XML document, I have to make a SelectNodes() call on an XmlDocument. It returns an isntance of XPathNodeList. I can call it several times but at one point, the result can't...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
11
by: vijaynats | last post by:
Why isn't there a 'throws' keyword in C# like java - i would like to declare a function and say - public int addup(int a, int b) throws ArithmeticExceptio, DivideByZeroException { ... ... }
1
by: Jozsef Bekes | last post by:
Hi All, I need to offer scripting possibilities in my app, and have to use MSSCriptControl for some reasons. I would like to use the feature that's called variable number of arguments, that is...
4
by: tzellman | last post by:
Ok, so here is my situation: Let's assume I have a function that makes good use of the kwargs parameter. It requires that there is a certain "format" for the kwargs keywords. (I am using Django,...
0
by: ujjwaltrivedi | last post by:
I had to use new char array and delete it. The application Crashes when i use delete keyword to deallocate char array. it throws an unhandled exception.
4
by: eusebiu | last post by:
Hello... I have an unaswered post on MSDN forum.... maybe you can help me... http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1625992&SiteID=1 Thanks
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
1
by: Bauklotz | last post by:
So, recently I've been experimenting with a telnet server, and a 5250 terminal emutator and I thought of making a field system, for easier graphical (well, not quite) displaying. This basically...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.