473,396 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,396 software developers and data experts.

Exceptions in C#

Hi,

In Java each method contains an optional throws statement with a list of
exceptions
thrown by the method.

Is there something similar that can be done in C#?

Ohad
--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail.bgu.ac.il
Nov 15 '05 #1
6 1280
Hi,

Yes in C# as well you can throw exceptions ...

public TestMethod( int i, int j)
{
try
{
...
...
// Called function may throw exception.
ExceptionMethod();
//Creates an instance of System.Exception and throws.
if( k == 0)
throw new Exception();
}
catch (Exception e)
{
}
Console.Writeline("Code after exception");
}
Nirosh.
"Ohad Young" <oh****@bgumail.bgu.ac.il> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
Hi,

In Java each method contains an optional throws statement with a list of
exceptions
thrown by the method.

Is there something similar that can be done in C#?

Ohad
--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail.bgu.ac.il

Nov 15 '05 #2
Ohad Young <oh****@bgumail.bgu.ac.il> wrote:
In Java each method contains an optional throws statement with a list of
exceptions thrown by the method.

Is there something similar that can be done in C#?


No, C# (and .NET in general) doesn't have checked exceptions.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
No. This reference may make things clearer:

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

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Ohad Young" <oh****@bgumail.bgu.ac.il> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
Hi,

In Java each method contains an optional throws statement with a list of
exceptions
thrown by the method.

Is there something similar that can be done in C#?

Ohad
--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail.bgu.ac.il

Nov 15 '05 #4
Ohad... This may help:

http://www.geocities.com/jeff_louie/OOP/oop5.htm
Chapter 5 "C++ and Java Gumption Traps"

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5
Hi Eric,

Thanks for the useful link, it was very helpful.

Bye, Ohad

"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:ef**************@TK2MSFTNGP10.phx.gbl...
No. This reference may make things clearer:

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

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights. "Ohad Young" <oh****@bgumail.bgu.ac.il> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
Hi,

In Java each method contains an optional throws statement with a list of
exceptions
thrown by the method.

Is there something similar that can be done in C#?

Ohad
--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail.bgu.ac.il


Nov 15 '05 #6
Hi Jeff,

Thanks for the useful link, it was very helpful.

Bye, Ohad

"Jeff Louie" <je********@yahoo.com> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
Ohad... This may help:

http://www.geocities.com/jeff_louie/OOP/oop5.htm
Chapter 5 "C++ and Java Gumption Traps"

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #7

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

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
9
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
14
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
8
by: cat | last post by:
I had a long and heated discussion with other developers on my team on when it makes sense to throw an exception and when to use an alternate solution. The .NET documentation recommends that an...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...
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,...
0
jinu1996
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...
0
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...
0
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,...

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.