Borland C ++ Builder 6中的异常处理问题(BCB 5.6) [英] exception handling problem in Borland C++ Builder 6 (BCB 5.6)

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

问题描述




我遇到了BCB 5.6的奇怪行为。例如:


#include< stdexcept>

#include< memory>


using namespace std ;


A级

{

公开:

A(){cout<< ; A construct.\ n; }

~A(){cout<< A destructed.\; }

};


无效主要()

{

尝试

{

auto_ptr< A> apA(新A);

抛出logic_error(太糟糕了!);

}

catch(some_except& e)

{

cout<< Exception cought: << e.what()<< " \ n";

}

}


输出:


A构造。

异常咳嗽:太糟糕了!


即不调用~apA()和~A()。 -xd选项(desctuctor

清理已启用)在IDE和命令提示符下都不起作用。


是否有人知道如何使用
borland编译器?


-

提前致谢。

解决方案

我不知道你的问题的答案,但我怀疑发布的

代码没有编译 - 你错过了一个标题而some_excpet是未知的。

如果改变如下:

- #include< stdexcept>

- #include< memory>

- #include< iostream> ;

-

-使用命名空间std;

-

-class A

- {

-public:

- A(){cout<< A construct.\ n; }

- ~A(){cout<< A destructed.\; }

-

- };


-int main()

- {

- 尝试

- {

- auto_ptr< A> apA(新A);

- 抛出logic_error(太糟糕了!);

- }

- catch(异常& e)

- {

- cout<< Exception cought: << e.what()<< " \ n";

- }


- 返回0;

- }

并使用g ++编译生成的可执行文件产生预期的

resault


martin @ ubuntu:〜


< blockquote> g ++ test.cpp -o hello

martin @ ubuntu:〜


./ hello

构建的。

被毁坏。

异常咳嗽:太糟糕了!

martin @ ubuntu:〜


Hi,

I encounter a strange behavior of BCB 5.6. The example:

#include <stdexcept>
#include <memory>

using namespace std;

class A
{
public:
A() { cout << "A constructed.\n"; }
~A() { cout << "A destructed.\n"; }
};

void main()
{
try
{
auto_ptr<A> apA(new A);
throw logic_error("Too bad!");
}
catch (some_except& e)
{
cout << "Exception cought: " << e.what() << "\n";
}
}

The output:

A constructed.
Exception cought: Too bad!

i.e neither ~apA() nor ~A() are called. -xd option (desctuctor
cleanup enabled) does not work both in IDE and command prompt.

Does anybody knows how to force the standard behavior with
borland compiler?

--
Thanks in advance.

解决方案

I do not know the answer to your question, but I suspect the posted
code is not compiling - you missed a header and some_excpet is unknown.
When changed like this:
-#include <stdexcept>
-#include <memory>
-#include <iostream>
-
-using namespace std;
-
-class A
-{
-public:
- A() { cout << "A constructed.\n"; }
- ~A() { cout << "A destructed.\n"; }
-
-};

-int main()
-{
- try
- {
- auto_ptr<A> apA(new A);
- throw logic_error("Too bad!");
- }
- catch (exception& e)
- {
- cout << "Exception cought: " << e.what() << "\n";
- }

- return 0;
-}

and compiled with g++ the resulting executable yields the expected
resault

martin@ubuntu:~


g++ test.cpp -o hello
martin@ubuntu:~


./hello
A constructed.
A destructed.
Exception cought: Too bad!
martin@ubuntu:~


这篇关于Borland C ++ Builder 6中的异常处理问题(BCB 5.6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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