Catch Exception treatment

前端 未结 5 1983
情歌与酒
情歌与酒 2021-01-14 10:25

What\'s the difference between using

catch(Exception ex)
{
   ...
   throw ex;
}

and using

catch   //  might include  (Exc         


        
5条回答
  •  不知归路
    2021-01-14 11:02

    Well, the first one will erase the stack trace, and replace it with where your throw is. The second one will throw the exception without altering the stack trace.

    Also, "catch" will catch ANYTHING that is thrown, whether it is an exception or not.

    The 2nd one is actually the equivalent of doing "catch(object)".

提交回复
热议问题