Is it bad programming style to have a single, maybe common, generic exception?

Posted by m0s on Stack Overflow See other posts from Stack Overflow or by m0s
Published on 2010-04-05T00:05:23Z Indexed on 2010/04/05 0:33 UTC
Read the original article Hit count: 295

Filed under:
|

Hi, so in my program I have parts where I use try catch blocks like this

try
{
  DirectoryInfo dirInfo = new DirectoryInfo(someString); 
 //I don't know if that directory exists
 //I don't know if that string is valid path string... it could be anything

 //Some operations here
}
catch(Exception iDontCareWhyItFailed)
{
  //Didn't work? great... we will say: somethings wrong, try again/next one
}

Of course I probably could do checks to see if the string is valid path (regex), then I would check if directory exists, then I could catch various exceptions to see why my routine failed and give more info... But in my program it's not really necessary. Now I just really need to know if this is acceptable, and what would a pro say/think about that. Thanks a lot for attention.

© Stack Overflow or respective owner

Related posts about programming-style

Related posts about c#