Exception Performance

Hi

I have a method and there are chances tht exception will occur
so i catch the General Excepion(i dont want to catch specific exp)
catch(Exception xx)
{
//Do some thing..
}

Since xx is not Used its giving a warning to avoid tht i replaced with empty catch.

I need to know wether the empty catch is a performance overhead.

catch
{
//Do some thing..
}

Since i need to catch all exceptions which is the best choice..



Answer this question

Exception Performance

  • Linlin425872

    You can replace:

    catch
    {
    ...
    }

    with:

    catch (System.Exception)
    {
    ....
    }

    to remove the warning.

    The only difference is that the first catch allows you to catch non-CLS-compliant exceptions (though you can't do anything with them).



  • n3zdh

    vidhyaprakash wrote:

    Hi

    I have a method and there are chances tht exception will occur
    so i catch the General Excepion(i dont want to catch specific exp)
    catch(Exception xx)
    {
    //Do some thing..
    }

    Since xx is not Used its giving a warning to avoid tht i replaced with empty catch.

    I need to know wether the empty catch is a performance overhead.

    catch
    {
    //Do some thing..
    }

    Since i need to catch all exceptions which is the best choice..

    Since you don't use the exception itself, the second option will do (and will be the best option). It will catch all exception but just won't store the information in an object (the exception object).



  • mprogrammer

    vidhyaprakash wrote:

    catch
    {
    //Do some thing..
    }

    This one is the fastest, but I can't imagine why you don't whant to log the exception...



  • Exception Performance