KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This question is close to what I want to do , but not quite there. Is there a way to simplify the following code? private bool ValidDirectory(string directory) { if (!Directory.Exists(directory)) { if (MessageBox.Show(directory + " does not exist. Do you wish to create it?", this.Text) == DialogResult.OK) { try { Directory.CreateDirectory(directory); return true; } catch (IOException ex) { lblBpsError.Text = ex.Message; } catch (UnauthorizedAccessException ex) { lblBpsError.Text = ex.Message; } catch (PathTooLongException ex) { lblBpsError.Text = ex.Message; } catch (DirectoryNotFoundException ex) { lblBpsError.Text = ex.Message; } catch (NotSupportedException ex) { lblBpsError.Text = ex.Message; } } } return false; } It seems a waste, and if I later want to change how I report an error back to the user, or perhaps I want to log these errors, or whatever, then I've got to change 5 different catch blocks. Am I missing something, or is this blatantly against code-reuse? Am I just trying to be (too) lazy?
Tags (comma-separated)
Save Edits
Cancel