I would say that it depends more on how you handle errors, and not how they are thrown. An example will help. Imagine this is a method instead of what you have:
public static int DoStuff(string o) { return Int.Parse(o); }
If you have it, then it really doesn't matter.
public static void main(string[] args) { try { Console.Write("Enter a number: "); value = DoStuff(Console.ReadLine()); } catch(Exception ex) { Console.WriteLine("An exception was thrown. Contents: " + ex.ToString()); } }
In any case, the flow of programs is the same. But if you have below:
public static void main(string[] args) { try { int value = 0; do { try { Console.Write("Enter a non-zero number to stop: "); value = DoStuff(Console.ReadLine()); } catch(ArgumentException ex) { Console.WriteLine("Problem with input, try again. Exception message was: " + ex.Message); continue;
Basically, if your error handling doesn't care what type of exception it is, then this is just extra code that probably won't help you. But if you handle certain things differently, then it may be useful to check and throw a more specific type of exception.
But I agree with Dmitryโs message above that the public method matters much more than the private one. Your signature for the method is somewhat similar to a contract. It is best to enforce it.
source share