您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

“ throw”和“ throw ex”之间有区别吗?

“ throw”和“ throw ex”之间有区别吗?

是,有一点不同;

throw 不会-原罪犯将得到保留。

static void Main(string[] args)

{ try { Method2(); } catch (Exception ex) { Console.Write(ex.StackTrace.ToString()); Console.ReadKey(); } }

private static void Method2() { try { Method1(); } catch (Exception ex) { //throw ex resets the stack trace Coming from Method 1 and propogates it to the caller(Main) throw ex; } }

private static void Method1() { try { throw new Exception(“Inside Method1”); } catch (Exception) { throw; } }

其他 2022/1/1 18:15:16 有440人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶