Does the Visual Studio's Help Index list all Exceptions?

F

felecha

I learned about Exceptions in School, and now that I'm building my
first real application on the job, I'm going through it trying to
analyze it for all possible Exceptions so I can handle them
effectively. I've been looking in the Help / Index for each Method's
documentation, and looking at the listed Exceptions. I'm finding a
number of methods with no Exceptions specified. Does that mean there
is no possible Exception for that method? Can I count on the
documentation in that way?

Like OleDbCommand.ExecuteReader. I'm using an Access database and
when I do a query that returns the resultset. No Exception is
listed. That method never throws an Exception???
 
R

Richard Myers

Hi Felecha

The documentation lists all exceptions thrown by the runtime.

For an exhaustive list look up exception, you will see this is subclassed by
SystemException, which is what the runtime uses as a base class for all its
exceptions and ApplicationException which the class you should inherit from
if you wish to create custom exceptions in your own applications.

With respect to OleDbCommand.ExecuteReader this does throw an exception
InvalidOperationException.
However more generally you will seek to catch the OleDbException thrown from
the datasource (Access2000).

In this case it is not the method but the Jet engine that is throwing the
exception hence the reason why you do not see it listed under
..ExecuteReader.

OleDbException inherits from InterOpServices.ExternalException which
inherits from SystemException.
If you need access to the HResult thrown by the Jet engine, check out the
ErrorCode property of the OleDbException.

You should also note that when you move up to SqlServer, OleDbException is
replaced by SqlException, which is governed by the same philosophy as
OleDbException, except that it is SqlServer specific.

Additionally just because a method doesn;t list an exception as being thrown
does not mean that by using that method no exceptional conditions can occur
that cause it's code to break. It just means the framework does not
explicity throw an exception when that given exception occurs.

This is a subtle but important difference.

Just as when you write code, you may expect a certain condition to be true
and if it is not, you may decide to throw an exception. However if an
exceptional condition occurs that you didn;t think about before releasing
your code library/app, then your code will still automatically throw an
exception, it's just that you personally have not explicitly thrown that
error and therefore it will not be documented in your help files. The same
is true for Microsofts code and docs for .Net.

If you do something really stupid with a method it will throw an exception
and if this hasn't been accounted for by the framework developers, then it
wont be documented.

hth
Richard
 
F

felecha

Thanks. I've read your reply carefully and am trying to digest it.
Every point is applicable and I need to think about it, I can see.

Thanks a lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top