Exception handling practices top level vs every function
.net, c#, exception
Solution
This depends on your application and is a design choice, though option 1 is very messy. You should only catch exceptions you are prepared to handle in someway, not arbitrarily catching every one. In most languages the exception will have a stack trace for you to look at so logging at every level is unnecessary. When I say handle in some way that may be to log and rethrow, or it may be to log, notify the user of some error, and continue to run
As a side note, you should not be using exceptions as logic in your code. If you find yourself using try catch blocks as flow control then you should think of a redesign. Exceptions are just that, exceptional.
Problem
I've seen several approaches of exception handling. Two most common patterns I've seen are: - try catch on every function, log the exception and rethrow - try catch on the top most level (Like main function), log the exception and rethrow Which is a better practice if there is one? Or what situations would you choose one approach over the another?