Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Long waited attempt to handle exceptions properly.

Reply
Thread Tools

Long waited attempt to handle exceptions properly.

 
 
Guest
Posts: n/a
 
      11-12-2003
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




 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      11-12-2003
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
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>



 
Reply With Quote
 
 
 
 
Natty Gur
Guest
Posts: n/a
 
      11-12-2003
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!
 
Reply With Quote
 
isaac nicolay
Guest
Posts: n/a
 
      11-12-2003
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.

http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.studentshopper.com/
 
Reply With Quote
 
Guest
Posts: n/a
 
      11-14-2003
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
><(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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
>>
>>
>>
>>

>
>
>.
>

 
Reply With Quote
 
Alvin Bruney
Guest
Posts: n/a
 
      11-15-2003
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
<(E-Mail Removed)> wrote in message
news:5a9301c3aac1$91362280$(E-Mail Removed)...
> 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
> ><(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed)...
> >> 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
> >>
> >>
> >>
> >>

> >
> >
> >.
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Dpreview post many have waited for nospam Digital Photography 12 12-30-2009 06:15 AM
Rita, the lens you've waited for is now in stock . .. ASAAR Digital Photography 5 07-05-2009 01:59 PM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
Sensor Cleaning While I Waited Dean S. Lautermilch Digital Photography 2 06-29-2005 12:44 PM
waited too long somebody@erols.com A+ Certification 2 11-20-2003 02:24 PM



Advertisments