C++ Exception catching and exception handling(2)

55 篇文章 0 订阅
16 篇文章 1 订阅

今天依旧说一下C++的异常处理,你可以参考我的上一篇博客:https://blog.csdn.net/m0_37690102/article/details/106389177

  • ---->Today,I still talk about c + + exception handling, you can refer to my last blog: https://blog.csdn.net/m0_37690102/article/details/106389177

C++的异常处理机制确实做的不够好,通过今天的实际测试发现,即使是标准异常,有些依旧还是不能很好的捕获。为了让出现异常的时候程序不崩溃,采用下面的代码:

  • ---->C++ 's exception handling mechanism is indeed not good enough, through today's actual testing found that even the standard exception, some still can not catch well.In order to prevent the program from crashing when an exception occurs, the following code is used:
try //核心功能函数进行异常捕获处理
{
	throw runtime_error("runtime_error");
}
catch (...)//捕获所有异常
{
	exception_flag = false;
	QDateTime current_date_time = QDateTime::currentDateTime();
	QString current_date = current_date_time.toString("yyyy-MM-dd hh:mm:ss ddd");
	QString fileName = ".//OCR.log";
	QString str = current_date + "----->"+"--catched:"+"未知异常"+"\r\n";
	QFile file(fileName);
	if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
	{
		;
	}
	QTextStream in(&file);
	in << str << "\n";
	file.close();
}

这种可以实现所有异常的捕获,但是具体是哪一种异常就很难知道。很奇怪的问题就是,昨天我用标准异常捕获可以捕获到异常,今天就不可以了。很是奇诡.

  • ---> This allows all exceptions to be caught, but it is difficult to know which one.The odd thing is, yesterday I was able to catch exceptions using standard exception catching, and today I can't.It's weird.

​​​I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值