In Java, calls to functions that can throw Exception
s need to anticipate them with either a try-catch
or by adding a throws Exception
to their function signature.
My main use for them is in my top-calling code, where I only put try-catch
es in sections that explicitly throw Exception
s.
However, because C# does not have checked exceptions, the only way I can think of anticipating Exception
s is to surround all sections of my top-calling code with try-catch
es. I personally do not like this approach for the following reasons:
It can lead to very messy code, putting
try-catch
es where they are not needed.I might miss a section that needs a
try-catch
.
How do I properly anticipate Exception
s in my top-calling code in C#?