473,385 Members | 1,730 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,385 software developers and data experts.

Type of error

Hi,
is it possible to determine exactly what type of error/exception was thrown
from a try catch block bt simple catching the generic error.

by this I mean, suppose I have the follwoing code

try
'do some database stuff
catch err as exception
'err now contains my error
end try

The most light error that accessing a db would throw is of type
System.Data.OleDb.OleDbException.
Do I need to specifically look for this type of excepotion in a catch block

try

catch err as System.Data.OleDb.OleDbException

catch err as exception
end try

or can I specifically tell from catching a generic error that it is of type
System.Data.OleDb.OleDbException.
I've noticed that certain methods can throw many types of exception so is to
best to have a catch handler for each type, or just have a generic catch
hanler and then from the object that is caught determine the type of
exception that was thrown.

cheers

alex.
Nov 17 '05 #1
1 1642
Good questions, Alex. As you've noticed, there are a large variety of types
of Exceptions. All Exceptions inherit System.Exception, so you can catch all
of them by putting a Catch block in for System.Exception. The .Net SDK does
a wonderful job of documenting the various types of Exceptions that can be
raised by the CLR classes, and it is often a good idea to include multiple
Catch blocks to catch the various types of Exceptions that may be thrown by
a certain operation, so that you can deal effectively with each one. Some
Exceptions can be recovered from in a number of ways, and knowing which type
you are dealing with can help you to write more effective Exception-handling
code. You can also use Reflection to discover what type of Exception was
thrown, and drill down into the InnerException of some Exceptions to find
out what Inner Exception caused the current Exception to be thrown.
Exceptions often cascade like this, and particularly when dealing with
database operations you may find an Inner Exception that was the original
cause of the problem.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Alex" <al**************@yahoo.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Hi,
is it possible to determine exactly what type of error/exception was thrown from a try catch block bt simple catching the generic error.

by this I mean, suppose I have the follwoing code

try
'do some database stuff
catch err as exception
'err now contains my error
end try

The most light error that accessing a db would throw is of type
System.Data.OleDb.OleDbException.
Do I need to specifically look for this type of excepotion in a catch block
try

catch err as System.Data.OleDb.OleDbException

catch err as exception
end try

or can I specifically tell from catching a generic error that it is of type System.Data.OleDb.OleDbException.
I've noticed that certain methods can throw many types of exception so is to best to have a catch handler for each type, or just have a generic catch
hanler and then from the object that is caught determine the type of
exception that was thrown.

cheers

alex.

Nov 17 '05 #2

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

Similar topics

3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
31
by: xah | last post by:
what's the pro and con of using <script language="javascript"> vs <script type="text/javascript"> Xah xah@xahlee.org ∑ http://xahlee.org/
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
7
by: Egyd Csaba | last post by:
Hi, I've a problem with some of my stored procs. My config is: RH7.1, Postgres 7.3.2 I had converted a few fields of a few tables from one type to another and after this I made all the...
4
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
13
by: =?Utf-8?B?S2VzdGZpZWxk?= | last post by:
Hi Our company has a .Net web service that, when called via asp.net web pages across our network works 100%! The problem is that when we try and call the web service from a remote machine, one...
25
by: SRR | last post by:
Consider the following code: #include <stdio.h> #include <string.h> struct test{ char a; } funTest( void ); int main( void ) {
1
by: urkel | last post by:
Hi everyone, I critically need help to solve this problem related to pointer in C++ Basically, I have a C/C++ program "retardselfenerg" calling a Fortran 90 subroutine "surfGF4.f90". i am so...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.