473,756 Members | 2,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1943
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(30 00);}
catch (InterruptedExc eption 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 "UserIsAMoronEx ception" 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(30 00);}
catch (InterruptedExc eption 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 InterruptedExce ption 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 InterruptedExce ption 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(30 00);}
catch (InterruptedExc eption 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 "UserIsAMoronEx ception" 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(30 00);}
catch (InterruptedExc eption 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
3588
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 be iterated. Here is the code: XmlNodeList nodes = _Document.SelectNodes(myXpathQuery); foreach(XmlNode n in nodes) { ... }
5
16607
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 extern storage class: /****************************************************************** SOURCE FILE ONE *******************************************************************/ extern int i; /* Reference to i, defined below */
11
34818
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
4085
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 done in C# using the params keyword. However, if I AddObject the instance to the MSScriptControl, and try to ivoke a function with variable number of arguments, the script throws an exception. I have exported the class signatrure to a tlb file, and...
4
1636
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, btw). The format is like such: "SOMEVAL__exact", etc., where SOMEVAL is some value that it parses from the keyword. Now, I want to call this function, specifying the kwargs. The problem is that I want to dynamically set the kwargs. For...
0
412
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
1417
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
2784
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 objHighLight As New highlight(Keyword, "<span class='searchKeyword'>{keyword}</span>") ContentFor = objHighLight.process(ContentFor, False, False) Return ContentFor 'Dim RegExp As Regex = New Regex(Keyword.Replace(" ", "|").Trim(),...
1
2549
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 lets you set the value of a X and Y position on the screen and it automatically updating it, and I needed to make the field_ variables global in order to use them in all the functions. The screen size variables work fine, but since it has many...
0
9431
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
10014
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9819
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
9689
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
8688
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
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
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.