Do I have to break after throwing exception?

前端 未结 6 1714
予麋鹿
予麋鹿 2021-01-03 20:58

I\'m writing a custom class in C# and I\'m throwing a couple exceptions if people give the wrong inputs in some of the methods. If the exception is thrown, will any of the c

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 21:24

    If you've wrapped your code in a Try...Catch...Finally block, then the code under Finally will always execute. For example:

    Try
      ' do some stuff here
      ' Examine user input
      If user input isn't valid
          Throw new exception
    Catch
       Throw ' Just re-throws the same exception
    Finally
       ' This code will execute, no matter what - exception or not
    End Try
    

提交回复
热议问题