473,326 Members | 2,173 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,326 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 1640
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.