简体   繁体   English

在C ++中捕获和重新抛出异常

[英]catching and re-throwing exceptions in c++

I am a java developer trying to maintain some very old c++ code (still have to use vs2010 to compile). 我是一名Java开发人员,试图维护一些非常古老的C ++代码(仍然必须使用vs2010进行编译)。

I am at home trying to understand exceptions without the ability to test stuff, so sorry if this question is stupid. 我在家里试图理解没有测试能力的异常,如果这个问题很愚蠢,请您谅解。

Can you throw an exception in a low level function and just catch it at the top, or does it have to be caught and re-thrown at every level? 您是否可以在低级别函数中引发异常并仅将其捕获在顶部,还是必须在每个级别捕获并重新抛出该异常?

This is complicated by the fact i am writing native code, calling managed code, calling c#, calling my java rest resource. 我正在编写本机代码,调用托管代码,调用c#,调用我的Java rest资源,这使情况变得复杂。 So are there any levels in there I absolutely have to catch and convert then re-throw. 因此,在那里我绝对必须抓住并转换然后重新抛出的任何级别。

Thank you in advance. 先感谢您。

Edit: as Jesper has answered the first half, can my native code handle system::exception? 编辑:正如Jesper回答了上半部分一样,我的本机代码可以处理system :: exception吗?

"Can you throw an exception in a low level function and just catch it at the top" - yes. “可以在低级函数中引发异常,并将其捕获在顶部吗?”-是的。

"does it have to be caught and re-thrown at every level?" “是否必须在每个级别上将其捕获并重新抛出?” - no. -不

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM