(I am actually using Ektron CMS, and am using Widgets
, which are a very simple extension of a user control).
Problem: I have a web page that contains many widgets. If an exception occurs in one of these widgets, the page stops and the user is given a server error. I would like to have unhandled exceptions in a widget to log the exception, stop display of that widget and allow the page to continue.
E.g. You have a weather widget on each page that gets data via a web service. If the web service sends you malformed XML, you would like the site to still be available.
Potential solutions:
Plan A) Within each widget, wrap contents of the init or display function in a Try-Catch statement.
Plan B) Create a new IRobustWidget interface which extends IWidget, and do the Try-Catch in there.
Both of these options seem a little "dirty" to me, as I've read that generic catch (exception)
statements are a bit of an anti-pattern. I'm leaning towards Plan B, as this seems more modular.
- Have I missed any other options?
- Is a generic Try-Catch ok in this regard?