Reducing duplicate error handling code in C#?

后端 未结 4 1326
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 19:08

I\'ve never been completely happy with the way exception handling works, there\'s a lot exceptions and try/catch brings to the table (stack unwinding, etc.), but it seems to

4条回答
  •  梦谈多话
    2020-12-29 19:29

    You could also use a more OO approach:

    • Create a base class that does the error handling and calls an abstract method to perform the concrete work. (Template Method pattern)
    • Create concrete classes for each operation.

    This has the advantage of naming each type of operation you perform and gives you a Command pattern - operations have been represented as objects.

提交回复
热议问题