Questions tagged «rethrow»

11
捕获和重新抛出.NET异常的最佳实践
捕获异常并重新抛出异常时应考虑哪些最佳实践?我想确保保留Exception对象的InnerException和堆栈的跟踪信息。以下代码块之间的处理方式是否有所不同? try { //some code } catch (Exception ex) { throw ex; } VS: try { //some code } catch { throw; }

4
重新抛出原始异常时的C ++异常问题
捕获中的以下append()是否会导致重新抛出的异常,以查看被调用append()的效果? try { mayThrowMyErr(); } catch (myErr &err) { err.append("Add to my message here"); throw; // Does the rethrow exception reflect the call to append()? } 同样,如果我用这种方式重写它,如果实际异常是由myErr派生的,会发生位切片吗? try { mayThrowObjectDerivedFromMyErr(); } catch (myErr &err) { err.append("Add to my message's base class here"); throw err; // Do I lose the derived …
117 c++  exception  rethrow 

2
Swift中的掷球和掷球有什么区别?
经过寻找一些参考的数字出来,-unfortunately-我找不到任何关于理解之间的差异有用-和简单-描述throws和rethrows。当试图了解我们应该如何使用它们时,这有点令人困惑。 我要说的是,我对-default-最为熟悉,它throws具有传播错误的最简单形式,如下所示: enum CustomError: Error { case potato case tomato } func throwCustomError(_ string: String) throws { if string.lowercased().trimmingCharacters(in: .whitespaces) == "potato" { throw CustomError.potato } if string.lowercased().trimmingCharacters(in: .whitespaces) == "tomato" { throw CustomError.tomato } } do { try throwCustomError("potato") } catch let error as CustomError { switch error { …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.