By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

Long waited attempt to handle exceptions properly.

P: n/a
Unfortunately I've used exception handling as a debugging tool.
Now I want to be smarter about handling errors. Today in the global.asx in the Application_OnError event, I inserted code to email me the Server.GetLastError with some other information.
Everythings working fine, but the information about the last error isn't useful. I stilll have to step through the program (VS.NET 2003) to find exactly where the error(s) originate.

Tell me if this is right.

1. The Code Behind uses and Object (dll).

2. Object uses another Data Access Object to retrieve data.

Here I know SQLException is being raised because I purposely changed the connect string.

I have no try catch blocks.

So......

If I throw Exceptions from the Data Access Object and the Code behind......will I receive more info about the error.

I'll give more detailed info...if needed, but someone with experience should know what I'm talking about.
While I'm testing myself.....I like hearing peoples opinions.

Thanks,
Lee


Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
the further away from the exception you catch it, the less likely you are to
have its context. catching errors at the global level is a last resort move.
you should try to catch at the page level before global. you should be
wrapping code with try catch blocks where you expect errors may occur so you
can handle them at this point and continue.

You may be able to glean more information from the Error property of the
Context object which returns the first exception object accumulated during
http processing.

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<le*********@hotmail.com> wrote in message
news:bo*********@enews2.newsguy.com...
Unfortunately I've used exception handling as a debugging tool.
Now I want to be smarter about handling errors. Today in the global.asx in the Application_OnError event, I inserted code to email me the
Server.GetLastError with some other information. Everythings working fine, but the information about the last error isn't useful. I stilll have to step through the program (VS.NET 2003) to find
exactly where the error(s) originate.
Tell me if this is right.

1. The Code Behind uses and Object (dll).

2. Object uses another Data Access Object to retrieve data.

Here I know SQLException is being raised because I purposely changed the connect string.
I have no try catch blocks.

So......

If I throw Exceptions from the Data Access Object and the Code behind......will I receive more info about the error.
I'll give more detailed info...if needed, but someone with experience should know what I'm talking about.

While I'm testing myself.....I like hearing peoples opinions.

Thanks,
Lee

Nov 17 '05 #2

P: n/a
Hi,

The innerExcaption property is holding the sql excaption data that
you're looking after.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3

P: n/a
You could add additional info to each catch like this

catch(Exception eX)
{
string sErr = "Error in blah.aspx, SomeFunction() " + eX.Message;
SendError(sErr);
}

plus any other relevent info so you know what file and what function
threw the error.

we*******@studentshopper.com
http://www.studentshopper.com/
Nov 17 '05 #4

P: n/a
Thank you,

I need to improve my developing of systems. Along with
commenting code, handling exceptions seemed be something
I only used while in debug mode.
If I catch an error before the last line of defense, most
of the time it's just to log the info and then I (by
habit) just throw a new exception with some additional
message.

If I just throw exceptions up the stack.....Is that
additional information going to appear at the global
level ?

I'm also looking for other uses besides logging and
sending messages. Or is that the primary use ?
-----Original Message-----
the further away from the exception you catch it, the less likely you are tohave its context. catching errors at the global level is a last resort move.you should try to catch at the page level before global. you should bewrapping code with try catch blocks where you expect errors may occur so youcan handle them at this point and continue.

You may be able to glean more information from the Error property of theContext object which returns the first exception object accumulated duringhttp processing.

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<le*********@hotmail.com> wrote in message
news:bo*********@enews2.newsguy.com...
Unfortunately I've used exception handling as a debugging tool. Now I want to be smarter about handling errors. Today in the global.asx
in the Application_OnError event, I inserted code to email me theServer.GetLastError with some other information.
Everythings working fine, but the information about
the last error isn'tuseful. I stilll have to step through the program (VS.NET 2003) to findexactly where the error(s) originate.

Tell me if this is right.

1. The Code Behind uses and Object (dll).

2. Object uses another Data Access Object to retrieve
data.
Here I know SQLException is being raised because I purposely changed theconnect string.

I have no try catch blocks.

So......

If I throw Exceptions from the Data Access Object and
the Codebehind......will I receive more info about the error.

I'll give more detailed info...if needed, but someone
with experienceshould know what I'm talking about.


While I'm testing myself.....I like hearing peoples

opinions.
Thanks,
Lee

.

Nov 17 '05 #5

P: n/a
The primary reason for rethrowing an exception is to interpret the catched
exception and interpret it as your own (add or retract information from it).
One gotcha is that when you rethrow, the run-time now only knows the point
of origin at the rethrow line. It doesn't know that the exception came from
deeper in the code so the rethrow becomes the point of origin. However, if
you append information from the original exception you can work around this.

There are lots of other uses, for example, you can redirect back to the
calling page so that the page starts over again automatically after a
critical error.
--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<an*******@discussions.microsoft.com> wrote in message
news:5a****************************@phx.gbl...
Thank you,

I need to improve my developing of systems. Along with
commenting code, handling exceptions seemed be something
I only used while in debug mode.
If I catch an error before the last line of defense, most
of the time it's just to log the info and then I (by
habit) just throw a new exception with some additional
message.

If I just throw exceptions up the stack.....Is that
additional information going to appear at the global
level ?

I'm also looking for other uses besides logging and
sending messages. Or is that the primary use ?
-----Original Message-----
the further away from the exception you catch it, the

less likely you are to
have its context. catching errors at the global level is

a last resort move.
you should try to catch at the page level before global.

you should be
wrapping code with try catch blocks where you expect

errors may occur so you
can handle them at this point and continue.

You may be able to glean more information from the Error

property of the
Context object which returns the first exception object

accumulated during
http processing.

regards

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
<le*********@hotmail.com> wrote in message
news:bo*********@enews2.newsguy.com...
Unfortunately I've used exception handling as a debugging tool. Now I want to be smarter about handling errors. Today in the global.asx
in the Application_OnError event, I inserted code to

email me the
Server.GetLastError with some other information.
Everythings working fine, but the information about

the last error isn't
useful. I stilll have to step through the program

(VS.NET 2003) to find
exactly where the error(s) originate.

Tell me if this is right.

1. The Code Behind uses and Object (dll).

2. Object uses another Data Access Object to retrieve

data.
Here I know SQLException is being raised because I purposely changed the
connect string.

I have no try catch blocks.

So......

If I throw Exceptions from the Data Access Object and

the Code
behind......will I receive more info about the error.

I'll give more detailed info...if needed, but someone

with experience
should know what I'm talking about.


While I'm testing myself.....I like hearing peoples

opinions.
Thanks,
Lee

.

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.