Try, Try Again

Posted by AgileCoder on May 22, 2008

Originally posted on my old Geekcyclist blog

As I detailed in a post a while ago, I find myself reviewing and updating a large amount of vb.net code that was written by a developer in our shop that moved on to greener pastures. Even though my background was originally in the BASIC world, I moved to C# when Visual Studio .Net 2002 was released and find that I really prefer it to vb.net. I have embraced the curly brace. So I have been converting as much as I can to utility classes in C#.

One of the great improvements of the .Net framework for VB was the Try-Catch-Finally style of error handling. However, just like GOTO, it can be misused and abused. The Pragmatic Programmer tip #34 is Use Exceptions for Exceptional Problems, and is an excellent read. But before you get there, you must have a basic understanding of how an exception is going to be handled.

With a few modifications (including translation to C#), this is a function that was in one of the projects I inherited.

public bool CheckStatus()
{
    try
    {
        SystemCheck();
    }
    catch(Exception)
    {
        SystemCheck();
    }
}

Trust me, it is unlikely that if SystemCheck() threw an exception the first time you called it that it will execute successfully when called again in the catch.

Here is another example:

public DataTable GetData()
{
    try
    {
        DataTable dt = new DataTable();
        /* Code here that:
        Built Command and Connection objects
        Adapter
        Filled Adapter
        */
    }
    catch(Exception)
    {
        //Do Nothing
    }
    finally
    {
        cn.Close();
        //more stuff snipped here
    }
    return dt;
}

The ‘Do Nothing’ has to be a HUGE red flag that there is something wrong.

If you know it might happen, handle it in the body of the function. Save the catch for things that are truly ‘exceptional’. When they happen, log the details, recover if you can, or fail gracefully.



cialis generika kamagra australia cialis preise cialis kaufen cialis bestellen levitra generika viagra online kaufen kamagra bestellen cialis generika kamagra oral jelly kamagra 100mg prix cialis cialis generique kamagra gel viagra prix viagra pour homme acheter cialis kamagra prix viagra pas cher cialis 20mg levitra 20
Levitra Generika kaufen Kaufen Levitra Generika Online Cialis ohne Rezept kaufen Viagra online Viagra Generika kaufen Cialis Soft Tabs kaufen Sildenafil kaufen Apcalis Oral Jelly kaufen Viagra Soft Tabs bestellen Cialis Original kaufen Viagra bestellen Viagra bestellen Propecia Generika kaufen Viagra und seine Analoga Original Testpakete Levitra und Kamagra Erfahrungen Viagra Soft Tabs Kamagra kaufen
kamagra kopen in de winkel viagra werking cialis kopen in nederland cialis bijwerkingen kamagra bijsluiter levitra bijwerkingen viagra kopen apotheek cialis erfaring cialis i norge viagra effekt hva er kamagra viagra nettbutikk levitra eller cialis kamagra gel comprar cialis efeitos secundarios viagra farmacia cialis bula viagra infarmed levitra comprimidos cialis vs viagra cialis flashback kamagra tjejer kamagra effekt levitra fass kamagra oral jelly opiniones levitra generico precio cialis venta kamagra sobres cialis efectos secundarios
Levitra Soft Cialis Professional Levitra Original Cialis Daily Red Viagra Cialis Jelly Acheter Levitra Viagra Professional Viagra Gold - Vigour Kamagra Jelly Viagra pour femme viagra kaufen cialis kaufen Erektile Dysfunktion Viagra Professional Viagra Jelly cialis online kopen Levitra Soft viagra voor vrouwen Viagra Soft
Prezzo Levitra Acquisto Red Viagra Acquisto Cialis Disfunzione Erettile Dopo Prostatectomia Radicale Acquisto Propecia Cialis Generico Viagra Originale senza ricetta Comprare Red Viagra Comprare Levitra Generico On Line Comprare Levitra Online Disfunzione Erettile Blocco Psicologico Levitra Vendita Comprare Propecia Acquisto Female Viagra Acquisto Cialis Jelly Viagra Super Active Levitra Originale Viagra online Levitra Compresse Divisibili Disfunzione Erettile Ecografia
Viagra Soft kamagra oral jelly cialis generisk viagra online viagra online Generisk Viagra Cialis Online Kvinnor Cialis Generisk Cialis Kvinnor Viagra Cialis Super Active Cialis soft viagra apoteket Kamagra Cialis Soft Viagra sverige Kamagra Gel Viagra Soft kamagra oral jelly Kamagra Online
kamagra gel comprar kamagra cialis pas cher cialis prix viagra generico cialis generico cialis prezzo comprare cialis cialis online viagra online
Levitra Vendita levitra Generico Farmacia On Line Vicenza Comprar Cialis Comprar Cialis comprar Kamagra Cialis Super Active Comprar Levitra Cialis Suisse Acheter Levitra Acheter Propecia viagra schweiz cialis kaufen Kamagra Bestellen erectiepillen kopen Cialis Kopen Viagra Viagra Professional Viagra Jelly cialis online kopen Levitra Soft
nike blazer michael kors Ray ban nike huarache Adidas Scarpe Abbigliamento Asics nike flyknit scarpe converse Scarpe air jordan scarpe da calcio nike free nike cortez nike roshe air max new balance oakley converse Scarpe Adidas scarpe Nike Scarpe louis vuitton Ray ban adidas Adidas superstar longchamp air max Cinture scarpe Puma Puma Scarpe Scarpe nike air max scarpe asics nike air force Saucony polo camicie Polo Ralph Lauren