在C中实现C ++的异常 [英] Implementing exceptions of C++ in C

查看:87
本文介绍了在C中实现C ++的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我不确定我是否应该在clc或clc ++上提出这个问题。让我试试

。我希望这对于这里的聪明人来说并不是太微不足道。

我知道之前已经在clc上询问了OOP问题,所以它可能是好的。


我是C ++的新手。 BS第3版声明:


%将转移控制转移给处理程序以进行例外处理....



%。 ..实现将根据需要展开函数调用堆栈,使

%回到该调用者的上下文。因此,投掷可以作为一种多层次的回报。


我的思维是如此C-ish我完全无法理解发生的事情。

我的笨脑这些预先要求。解释用法和想法


抛出

例外

试试

catch


带有C ++代码和C中的并行代码。如果必须涉及goto',请继续。

但翻译必须尽可能高度并行。此外,如果

你有办法描述这个,并通过函数调用堆栈补充

图表,那就更好了。


谢谢++,


-


, - 。 Bernard Klein,德国柏林,=, - _-。 =。

/, - )((_ /)oo(\_))

\` - ''` - ''(。)` - ''

` - 。 \_ /

解决方案

Bernard写道:

大家好,
我不确定我是否应该在clc或clc ++上提出这个问题。让我试试
两者。我希望这对于这里的聪明人来说并不是太微不足道。
我知道之前已经在clc上提出了OOP问题,所以它可能是好的。

我是C ++的新手。 BS第3版声明:

%将控制转移到异常处理程序....

%...实现将根据需要展开函数调用堆栈得到
%回到该调用者的上下文。因此,投掷可以作为一个多层次的回归。

我的思绪是如此C-ish,我完全无法理解发生了什么。
我的愚蠢的大脑有这些预先要求。用C ++代码和C语言中的并行代码解释

使用
尝试

的用法和想法。它必须涉及转到',继续。
但翻译必须尽可能高度并行。此外,如果您有某种方式来描述这一点,并通过函数调用堆栈图表补充,那就更好了。



我不喜欢我认为在C中有一种干净的复制方式。否则

我们都会这样做!它需要在C ++中运行时支持,所以你不能用b b b制作一个独立的C ++应用程序,除了你需要链接一个运行时。


C也不会创建对象。在C ++意义上(没有

析构函数的概念),所以当堆栈解开时你不能销毁它们。


Ian




" Ian" <无*** @ nowhere.com>在消息中写道


我不认为在C中有一种干净的复制方式。否则
我们都会这样做!它需要C ++中的运行时支持,所以你不能制作一个独立的C ++应用程序,除非你需要链接运行时间。

那可能是在你的平台上是真的,因为异常需要很多额外的代码,这些代码可能在某个库中。但是,为什么包含例外的C ++程序不能单独存在,而且C不会创建对象,这也是没有原因的。
固有的原因。在C ++意义上(没有析构函数的概念),所以当堆栈解开时你不能销毁它们。



这就是问题所在。在C中实现异常处理是非常困难的,当然可以是任何人类可用的形式。


2004-04-17 ,Bernard< ob ********** @ others.net>写道:

我是C ++的新手。 BS第3版声明:

%将控制转移到异常处理程序....

%...实现将根据需要展开函数调用堆栈得到
%回到该调用者的上下文。因此,投掷可以作为多层次的回报。

我的思想是如此C-ish,我完全无法理解正在发生的事情。


考虑来自< setjmp.h>的setjmp()和longjmp()。类比不是完美的,但是longjmp()充当了多层次的回报。

我的愚蠢大脑有这些预先要求。用C ++代码和C中的并行代码解释

抛出
异常的用法和想法


/ blockquote>


请参阅: http:// www.nicemice.net/cexcept/


- 詹姆斯


Hi All,

I am not sure if I should be asking this question on clc or clc++. Let me try on
both. I hope that this is not too trivial for the brilliant minds over here.
I know that OOP questions have been asked on clc before so it is probably OK.

I am a newbie to C++. BS 3rd edition states:

% The throw transfers control to a handler for exceptions ....
%
% ... the implementation will unwind the function call stack as needed to get
% back to the context of that caller. Thus throw acts as a multilevel return.

My mind is so C-ish that I totally fail to comprehend what is going on.
My dumb brain has these pre-reqs. Explain the usage and idea of

throw
exception
try
catch

with a C++ code and a parallel code in C. If it must involve goto''s, go ahead.
But the translation must be as highly parallel as possible. Furthermore, if
you have some way to depict this, and supplement by "function call stack"
diagrams, all the better.

Thanks++,

--

,--. Bernard Klein, Berlin, Germany ,= ,-_-. =.
/ ,- ) ((_/)o o(\_))
\ `-'' `-''(. .)`-''
`-. \_/

解决方案

Bernard wrote:

Hi All,

I am not sure if I should be asking this question on clc or clc++. Let me try on
both. I hope that this is not too trivial for the brilliant minds over here.
I know that OOP questions have been asked on clc before so it is probably OK.

I am a newbie to C++. BS 3rd edition states:

% The throw transfers control to a handler for exceptions ....
%
% ... the implementation will unwind the function call stack as needed to get
% back to the context of that caller. Thus throw acts as a multilevel return.

My mind is so C-ish that I totally fail to comprehend what is going on.
My dumb brain has these pre-reqs. Explain the usage and idea of

throw
exception
try
catch

with a C++ code and a parallel code in C. If it must involve goto''s, go ahead.
But the translation must be as highly parallel as possible. Furthermore, if
you have some way to depict this, and supplement by "function call stack"
diagrams, all the better.


I don''t think there is a clean way of replicating this in C. Otherwise
we''d all be doing it! It requires run time support in C++, so you can''t
make a stand alone C++ app with exceptions, you have to link a run time.

Also C doen''t create "Objects" in the C++ sense (no concept of a
destructor), so you can''t destroy them as the stack is unwound.

Ian



"Ian" <no***@nowhere.com> wrote in message


I don''t think there is a clean way of replicating this in C. Otherwise
we''d all be doing it! It requires run time support in C++, so you
can''t make a stand alone C++ app with exceptions, you have to
link a run time.
That might be true on your platform, because exceptions require a lot of
extra code which might be in a library somewhere. However there is no
inherent reason why C++ program including exceptions can''t be standalone
exectutables.
Also C doen''t create "Objects" in the C++ sense (no concept of a
destructor), so you can''t destroy them as the stack is unwound.


This is the problem. It is extremely difficult to implement exception
handling in C, certainly in any form that is human-usable.


On 2004-04-17, Bernard <ob**********@elsewhere.net> wrote:

I am a newbie to C++. BS 3rd edition states:

% The throw transfers control to a handler for exceptions ....
%
% ... the implementation will unwind the function call stack as needed to get
% back to the context of that caller. Thus throw acts as a multilevel return.

My mind is so C-ish that I totally fail to comprehend what is going on.
Consider setjmp() and longjmp() from <setjmp.h>. The analogs are not
perfect, but longjmp() acts as a multilevel return.
My dumb brain has these pre-reqs. Explain the usage and idea of

throw
exception
try
catch

with a C++ code and a parallel code in C.



See: http://www.nicemice.net/cexcept/

-- James


这篇关于在C中实现C ++的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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