删除try catch块会导致coredump [英] Does removal of try catch block lead to coredump

查看:303
本文介绍了删除try catch块会导致coredump的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道删除try catch块何时会导致核心转储

解决方案

不完全正确。要回答这个问题,您需要了解异常的工作原理。理解的关键是:它们传播回到堆栈。要理解这一点,您还需要了解常规调用堆栈的工作方式(不要与构建在堆栈机制之上的异常堆栈混淆),这就是所有的回调系统都是基于,局部变量和传递函数参数。



结构异常处理作为一种时间机器。我试着在这里解释一下:

C#构造函数中的异常会导致来电者分配到失败? [ ^ ] ,

存储位置操作系统中的.net异常 [ ^ ]。



现在,如果您从未处理过某些顶级堆栈框架的异常,会发生什么线程,或者如果你只处理其中的一些?这取决于那是什么线程。考虑主线程。异常在堆栈中向上和向上传播,直到传播跳转到最终调用入口点 main 函数的某个运行时组件。那么它取决于这个组件的作用。它可能会产生转储。或不。对于其他线程,线程只是终止。处理未处理的异常可能会也可能不会发生。通常,它不会发生,除非某些运行时机制在线程机制之上保留一些处理。



上面解释的所有场景都是异常的。首先,您应该尽可能少地处理异常,避免在本地处理它们。你必须在我称之为能力点的特殊点上进行。同时,您必须最终捕获每个线程的顶部堆栈帧上的所有异常。 UI线程通常需要在最大事件驱动循环的顶层堆栈帧上进行处理,并从异常中恢复以在所有情况下继续循环。 UI库通常有预定义的机制。



我也回答过去的答案:

从网络摄像头拍摄的图像未保存在服务器上 [ ^ ],

未处理的例外:访问违规 [ ^ ],

如何在托管c ++类中捕获本机c ++异常? [ ^ ],

当我运行一个应用程序时,会遇到如何处理这个异常的情况? [ ^ ]。



我引用的一些答案是关于.NET的。不要混淆:它没关系,我的所有考虑也适用于C ++,或几乎任何其他。



-SA

I want to know when will the removal of try catch block leads to core dump

解决方案

Not exactly. To answer this question, you need to understand how exception works. The key to understanding is this: they propagate back to stack. To understand that, you also need to understand how the regular call stack works (not to be mixed up with exception stack built on top of the stack mechanism), this is what all the call-return system is based on, as well local variables and passing function parameters.

Structural exception handling acts as a kind of "time machine". I tried to explain it here:
Does Exception in C# Constructor Cause Caller Assignment to Fail?[^],
where was stored .net exceptions in operating system[^].

Now, what happens if you never handle exceptions up to the top stack frame of some thread, or if you handle only some of them? It depends on what thread is that. Consider the main thread. The exceptions propagate up and up the stack, until the propagation jumps to some runtime component which ultimately called your entry point, main function. Then it depends on what this component does. It may produce the dump. Or not. For other threads, the thread just terminates. The handling of unhandled exceptions may or may not happen. Normally, it doesn't happen, unless some runtime mechanism reserved some handling on top of threading mechanism.

All the scenarios explained above are abnormal. First of all, you should handle exceptions as little as possible, avoid handling them too locally. You have to do it only in special points I call "competency points". At the same time, you have to ultimately catch all exceptions somewhere on the top stack frame of each thread. UI threads usually need handling on top stack frame of the biggest event-driven loop and recover from exceptions to continue the loop in all cases. UI library usually have predefined mechanism for that.

Se also my past answers:
Image taken from Webcam not getting saved on the server[^],
Unhandled Exception : Access Violation[^],
How do I catch native c++ exception in managed c++ class?[^],
When i run an application an exception is caught how to handle this?[^].

Some of my answers I referenced are about .NET. Don't be confused with that: it just doesn't matter, all my considerations are also applicable to C++, or almost anything else.

—SA


这篇关于删除try catch块会导致coredump的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆