Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie: Show that function might throw exception

0 views
Skip to first unread message

Joachim

unread,
Feb 12, 2005, 11:01:02 AM2/12/05
to
Is there any way of clearly showing to the programmer that an exception might
be thrown from a function? In C++ you can write:

void MyClass::MyFunction(...) throw (MyException);

Is there anything similar in C#?

Thanks in advance

Joachim

unread,
Feb 12, 2005, 11:01:04 AM2/12/05
to

Amy L.

unread,
Feb 12, 2005, 11:09:02 AM2/12/05
to
I am not sure if I understand your question 100%, but an exception can be
thrown from any method. If you are asking how to do it you can do something
like this

if ( myValue != WhatItShouldBe )
throw new Exception(....) ;

You can also write custom exception classes that inherit Exception.

Amy

"Joachim" <Joa...@discussions.microsoft.com> wrote in message
news:E294077C-89F1-46ED...@microsoft.com...

Joachim

unread,
Feb 12, 2005, 11:33:02 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another
programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:33:03 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:33:05 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:35:10 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:35:05 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:35:04 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:35:17 AM2/12/05
to

Joachim

unread,
Feb 12, 2005, 11:35:13 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:35:13 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:35:11 AM2/12/05
to
Hi Amy and thanks for your reply,

No. What I meant was if there is a way for me, as a programmer that develops
libraries that other programmers can use, to show to the other programmers
that the function that they can use can throw an exception. For instance,
I've been trying out the MySQLDriverCS library to connect to a MySQL
database. When typing the name of a function of an object created which
belongs to that API, and then selecting "Go to definition" I will only get an
"Object browser" which shows the functions available, but in that (nor in
the documentation...) view I cannot see any information about whether the
function throws any exception that I might have to catch. When writing

void MyClass::MyFunction(...) throw (MyException);

in C++ "throw (MyException) is only a way of clearly showing to another

programmer what he / she (perhaps) have to deal with when it comes to
exceptions.

Joachim

unread,
Feb 12, 2005, 11:37:06 AM2/12/05
to
I'm so sorry for my multiple posts, but every time I try to post something I
get an error message back so I tried to post the post again. Hope MS can fix
this problem.

Joachim

unread,
Feb 12, 2005, 11:39:03 AM2/12/05
to

Joachim

unread,
Feb 12, 2005, 11:39:02 AM2/12/05
to

Jeff Louie

unread,
Feb 12, 2005, 12:54:25 PM2/12/05
to
Joachim... C# does not support checked exceptions. One approach is to
explicitly state the pre-conditions that result in an exception in the
method
summary. It is up to the user of the method to read the documentation
and
validate the preconditions. If the user does this, then the user should
not
need to catch the exception. If the exception is from an invariant
violation or
post condition you could add WithExceptions to the method name.

http://www.geocities.com/jeff_louie/OOP/oop14.htm

Regards,
Jeff


>Is there any way of clearly showing to the programmer that an exception
might be thrown from a function?<

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

Italo Silveira

unread,
Feb 12, 2005, 1:00:38 PM2/12/05
to
What about using the C# documentation feature to do this?

<exception cref="member">description</exception>

Italo


"Joachim" <Joa...@discussions.microsoft.com> wrote in message

news:D652A018-A37B-42A4...@microsoft.com...

0 new messages