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

后端 未结 10 2649
陌清茗
陌清茗 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 11:11

    This will might get downvoted but doesn't c# have goto(note I have almost no c# knowledge so I have no idea if this works).

    what about something like

    try 
    { 
    ...
    } 
    catch(Exception ex) 
    { 
    ...
    goto Jump_past_tryelse
    } 
    ...//Code to execute if the try block DID NOT fail
    
    Jump_past_tryelse:
    ...
    

提交回复
热议问题