C#: Equivalent of the python try/catch/else block

后端 未结 10 2656
陌清茗
陌清茗 2021-02-15 10:53

In Python, there is this useful exception handling code:

try:
    # Code that could raise an exception
except Exception:
    # Exception handling
else:
    # Cod         


        
10条回答
  •  误落风尘
    2021-02-15 10:58

    Barbaric solution: create an Else class derived from Exception, throw an instance of it at the end of the try block, and use catch (Else) {...} to handle the other stuff.

    I feel so dirty.

提交回复
热议问题