I am reading some settings from a config file that would be setup by different developers. They can choose to add different settings and leave out other ones. In by abstract classes constructor, I want to read those settings, but I don't want to fail if they don't exist. So my question is, which is more efficient: using a try with an empty catch block, or using a try with an empty finally block? Again, I don't want to do anything if there's an exception.
If you're worried about efficiency you're worried about the wrong thing. One of those will catch and consume the exception the other will let the exception propagate. Empty finally blocks serve no purpose at all
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
If you want to do something with an exception - even ignore it, you'll need a catch regardless of performance. (which basically is only a factor if an exception occurs)
The ConfigSectionHandler is your own class (I cannot find it anywhere)? Implenet a test method like SettingExists to test if the desired setting is there or not. Try-catch is intended to deal with unexpected conditions, but absence of the setting is expected, it is one of regular states, in which the setting can be, nothing expectional.
P.S. If I could advise you, never do empty catch block, at least log the exception, otherwise the exception is consumed and you could be in trouble while investigating why something goes wrong
Bookmarks