How Can I Force Execution to the Catch Block?

后端 未结 12 1338
野趣味
野趣味 2021-01-17 07:46

I am wondering can try..catch force execution to go into the catch and run code in there?

here example code:

try {
    if (         


        
12条回答
  •  半阙折子戏
    2021-01-17 07:53

    Yes, you have to throw exception :

      try
      {
        throw new Exception("hello");
      }
      catch (Exception)
      {
    
         //run some code here...
      }
    

提交回复
热议问题