Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Is "Try Catch" slow?Is "Try Catch" slow?
Previous
 
Next
New Post
6/21/2008 7:53 AM
 

i recommend you don't wrap entire pages/functions in try catch blocks, they should be used granularly i.e. wrap them around the individual instruction(s) that may fail. If there is an error in an area that's not wrapped up in a block it will bubble up scope, first to any enclosing block such as sub/function, then to the page, then to the application. If you want a "catch-all" at page level, better to add a delegate to a function or use the page_error event.

Cathal


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
6/23/2008 5:55 AM
 

Cathal

Thank you very much for your recommendation. But:

  1. Everything ok with Try Catch for modules.
  2. Our thread was for httpModule

After detailed search we think that for httpModule enough one Try Catch block (like you said it will be like bubble). Some developers say that good code does not need Try Catch at all, because good code should verify everything what he use. We do not agreed with it, because there is not "ideal code", so will use one "Try...Catch" to protect.

Thanks for all who has helped :)

Sergey

 
New Post
6/23/2008 12:01 PM
 

Hi Sergey,

Maybe a bit more context would be useful.  Are you actually catching an exception during every httpModule call?  If so, that's not really an exceptional circumstance and you should handle the erroneous occurrence during your normal code flow.  Have you tried benchmarking with a release build?  What were the speed differences?

Here's another bit of advice that will probably cause some controversy: don't catch the base exception class (catch ex as System.Exception).  I wonder if that's not what you're already doing, and possibly obscuring some unanticipated exceptions.

Finally, don't wrap your entire method in one big Try-"Catch Exc as Exception" monster.  I know of one unnamed awesome application that does this all the time, and it drives me crazy!

Brandon


Brandon Haynes
BrandonHaynes.org
 
New Post
6/23/2008 12:09 PM
 

One more comment before I'm (probably) done -- Nick Guerrera discusses some good exception handling philosophy here in the context of static code analysis.  He deals mostly with exception handling from the framework perspective, and there are (arguably) some presentation-level exceptions, but it's a good primer.  Nick is a smart guy.

Be sure to read the comments, I recall some good ensuing discussion. 

Brandon


Brandon Haynes
BrandonHaynes.org
 
New Post
6/23/2008 1:26 PM
 

Cathal is correct to a degree in that Try/Catch in itself is not slow.

However, processing an exception is slower than having no exception.  So in summary. from slowest to fastest we have:

  1. Do not handle exception
  2. Handle the exception with Try/Catch
  3. Rewrite your code to avoid exceptions

If you find that you are getting an exception raised consistently then your code should be rewritten to avoid the exception. 

For instance, if you are getting a null reference exception from trying to access a property or method of a null object, then rather than use try/catch you should use -- if (object != null).  This would be much faster.

I realise that this is not always possible.

 


Charles Nurse
Chief Architect
Evoq Content Team Lead,
DNN Corp.

Want to contribute to the Platform project? - See here
MVP (ASP.NET) and
ASPInsiders Member
View my profile on LinkedIn
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Is "Try Catch" slow?Is "Try Catch" slow?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out