Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it ok to have a try/catch in a finally?

Tags:

c#

is that an "ok" code?

        try
        { /*stuff*/ }
        catch (Exception e)
        { /*stuff*/ }
        finally
        {
            try
            { /*stuff*/ }
            catch { /*empty*/ }
        }

I need to do complex operation in the finally and it might crash since it's connecting to the a DB

this look weird to me, so. is this the proper way?

like image 353
Fredou Avatar asked Nov 01 '11 14:11

Fredou


1 Answers

This is really going to depend on what you are doing, but personally, if it is truly after the other try catch and done after the operation I wouldn't nest it in a finally, just treat it as another try catch. That would remove some of the "oddity" in it.

like image 148
Mitchel Sellers Avatar answered Sep 29 '22 11:09

Mitchel Sellers