Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

telerik -- supercharge your DNN websites
  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
The best choice for your web site host, email hosting, and domain registration.
 


  Sponsors  

Meet Our Sponsors

Portal Webhosting - Hosting For Developers
Red-Gate Software
MaximumASP
SourceGear - Tools for Developers
.: CounterSoft :.
telerik
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  Is "Try Catch" slow?
Previous Previous
 
Next Next
New Post 6/23/2008 1:04 PM
User is offline Fooberichu
424 posts
www.seeleyware.com
8th Ranked


Re: Is "Try Catch" slow? 

And just my 2 cents to add to Charles... programming with try catch as FUNCTIONALITY is bad practice.  In other words, I'll use an example: In the .NET 1.x world lets say you wanted to convert some string data to a numeric but you had no way of knowing if the data coming in is actually representable by a number.  You could use the Convert.ToInt32(someString) (returns 0 if it can, might throw an exception though if the string is way out of whack) or maybe you could have written something like try { someNum = Int32.Parse(someStringRepresentation); } catch (System.Exception ex) { // logic here } (and as somebody mentioned you'd actually not use the general System.Exception class, but something more specific).  While this is "ok", if you try to run this same operation on thousands of strings and a good portion of them are failing, you'll see this has a huge performance hit.  So as Charles mentioned, you'd want to do something to check and make sure it'd work.  .NET 2.0 added a TryParse method which basically uses Regex or some other method to check before attempting to parse, increasing the speed and performance drastically.

Try/Catch should only be used to catch REAL exceptions.  In other words, something could possibly happen here out of the norm such as an invalid IO operation (network drive lost, maybe?)... not that my bad coding is going to produce errors.  Embedding an entire huge piece of functionality in a try/catch is lazy and irresponsible of a programmer -- you should seek out, as Charles suggested, the root of the problem and prevent those errors from being there in the first place.


-- Fooberichu
http://www.seeleyware.com
 
New Post 6/27/2008 3:18 AM
User is offline FreeDotNetNuke
153 posts
freedotnetnuke.com
9th Ranked


Re: Is "Try Catch" slow? 

Brandon

hmm, its a bit confused

"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!"

In generally we were making it very often :( Can you explain a bit more 2 things:

  1.  Why we do not need to use "System.Exception". Could be we do not know what type of exception will be?
  2. Why we do not need to use single Try Catch per control (like "bubble " as Cathal has said)?

Thank you for your help!

BTW: No problems with httpModule now. Everything works very fast. We had refactored our code. Also we do not use Try Catch at all. Only code validators like "if(obj==null)" or something like this.

Sergey


Client always right!
Pages Administration with Drag&Drop for DotNetNuke
List Of All Modules From FreeDotNetNuke
 
New Post 6/27/2008 3:27 AM
User is offline FreeDotNetNuke
153 posts
freedotnetnuke.com
9th Ranked


Re: Is "Try Catch" slow? 

Charles && Fooberichu

Thank you very much for your comments. In generally problem has been solved. We did not use Try Catch, all verifications are in the code. We do not want to make more bad code (there are a lot already :( we have to fix it everyday from different clients from old developers :(

Thank you for your help.

Only one question still opened for Brandon is about "System.Exception" - why we should not use it?

Sergey


Client always right!
Pages Administration with Drag&Drop for DotNetNuke
List Of All Modules From FreeDotNetNuke
 
New Post 6/27/2008 4:18 AM
User is offline Joe Brinkman
1244 posts
www.dotnetnukecorp.com
6th Ranked






Re: Is "Try Catch" slow? 

Sergey,

It is a good practice to be explicit about the types of exceptions you expect to catch so that you can have specific logic for those cases.  Then you can have a fallback exception handler for those cases where you don't know which exception will be thrown.  This means that instead of using a simple try/catch, use multiple catch statements:

try
{
    //Do some work
}
catch (System.IO.FileLoadException fex)
{
    //What to do if I can't load the file
}
catch (Exception ex)
{
    //Not sure what happened
}


Joe Brinkman
DotNetNuke Corp.

The Accidental Geek - Joe Brinkman

 
New Post 7/5/2008 4:02 AM
User is offline FreeDotNetNuke
153 posts
freedotnetnuke.com
9th Ranked


Re: Is "Try Catch" slow? 

Joe

Super! Thank you very much! Its really cool example. I like it a lot and will use in future.

Thank you

Sergey


Client always right!
Pages Administration with Drag&Drop for DotNetNuke
List Of All Modules From FreeDotNetNuke
 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  Is "Try Catch" slow?
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


telerik
telerik r.a.d.controls suite is the most innovative and comprehensive toolset for ASP.NET development, tailored for seamless integration with the DotNetNuke project. This integrated collection of controls allows professionals to build web-solutions with the UI richness and responsiveness of desktop applications.
dnn.telerik.com
CrystalTech
CrystalTech Web Hosting™ provides first-class service and support. Our value-packed ASP.NET plans offer DNN installation, SQL 2005 and up to 100 domain names starting at only $16.95 per month!
CrystalTech.com
DotNetNuke® in Sweden
All service of DotNetNuke® in Sweden.
Olsmar Konsult

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP