try catch - Two different ways of "catching" two different kinds of exceptions in C#. Is one better than another? -


i've never had need catch more 1 exception @ time before. here's scenario. want "try" copy file. if destination doesn't exist, don't want bothered it. still want catch other type of exception. unauthorizedaccessexception example. below 2 things i've tried, i've seen both examples used on web. 1 better coding another. or completly wrong on both? thanks.

        catch (directorynotfoundexception)         {             // nothing         }         catch (exception ex)         {             messagebox.show(ex.message);         } 

or

        catch (exception ex)         {             if (ex directorynotfoundexception)             {                 // nothing                 return;             }             else             {                 messagebox.show(ex.message);             }         } 

imho, having multiple catch reduce code-readability. suggest.

if (directory.exists(dirpath))         {             try             {                 file.copy(sourcefile, destfile);             }             catch (exception msg)             {                 //handle exception.             }         } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -