Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
C++_cpp
Cpp异常Exception
C++里面异常处理官方例程运行有错误
发布于 2020-11-17 17:04:41 浏览:1045
订阅该版
- 按照文章[在 STM32 上使用 C++ 指南](https://www.rt-thread.org/document/site/application-note/components/cplusplus/an0035-cpp/)的讲解 - 运行文档中给的C++测试例程出现错误: > 程序为 > ``` > #include
> #include
> > #define MIN_VALUE (1e-4) > #define IS_DOUBLE_ZERO(d) (abs(d) < MIN_VALUE) > > double div_func(double x, double y) > { > if (IS_DOUBLE_ZERO(y)) > { > throw y; /* throw exception */ > } > > return x / y; > } > void throw_exceptions(void *args) > { > try > { > div_func(6, 3); > rt_kprintf("there is no err\n"); > div_func(4, 0); /* create exception*/ > rt_kprintf("you can run here\n"); > } > catch(double) /* catch exception */ > { > rt_kprintf("error of dividing zero\n"); > } > } > > MSH_CMD_EXPORT(throw_exceptions, throw cpp exceptions); > ``` > 运行时报错为 > ``` > \ | / > - RT - Thread Operating System > / | \ 4.0.3 build Nov 17 2020 > 2006 - 2020 Copyright by rt-thread team > RTT Control Block Detection Address is 0x200024b0 > msh >throw_exceptions > there is no err > thread:tshell abort! > > ``` - 经过调试发现,程序中throw的y没被catch,转而执行到rtthread/components/libc/compliers/newlib/syscalls.c中的abort函数 ``` void abort(void) { if (rt_thread_self()) { rt_thread_t self = rt_thread_self(); rt_kprintf("thread:%-8.*s abort!\n", RT_NAME_MAX, self->name); rt_thread_suspend(self); rt_schedule(); } while (1); } ``` - 请问是为什么?
查看更多
1
个回答
默认排序
按发布时间排序
还没想好
2020-12-25
这家伙很懒,什么也没写!
使用 GCC 编译器试试?
撰写答案
登录
注册新账号
关注者
0
被浏览
1k
关于作者
1067815899
这家伙很懒,什么也没写!
提问
12
回答
0
被采纳
0
关注TA
发私信
相关问题
1
RT-STUDIO下加入TOUCHGFX?
2
有没有人在RTT上使用C++编程
3
nano c++ 报错如何处理
4
让成员函数能作为rt_device中的回调函数
5
成员函数作为回调函数
6
C++编译问题 undefined reference to `_exit'
7
开启C++功能后,rt_kprintf和单步调试功能无法使用
8
RT-Thread Studio C++ 异常处理 (与预期不一致)
9
C++继承Thread类报错怎么办?
10
STM32使用C++ 编译报错
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
国产MCU移植系列教程汇总,欢迎查看!
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
FRDM-MCXN947开发板之i2c应用
2
esp32 s3使用cherryusb cdc
3
【Vision Board 创客营】Vision Board上的DAC实践
4
【Vision Board创客营连载体验】RA8D1 Vision Board 实现 FAL 同时调用片上以及外挂 Flash
5
NXP MCXN947开箱照
热门标签
RT-Thread Studio
串口
LWIP
SPI
Env
Bootloader
AT
ART-Pi
Hardfault
CAN总线
FinSH
USB
文件系统
DMA
RT-Thread
SCons
线程
RT-Thread Nano
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
ota在线升级
WIZnet_W5500
I2C_IIC
UART
flash
cubemx
packages_软件包
freemodbus
PWM
潘多拉开发板_Pandora
定时器
ADC
BSP
中断
编译报错
socket
keil_MDK
GD32
MicroPython
msh
Debug
ulog
SFUD
flashDB
SDIO总线
rt_mq_消息队列_msg_queue
本月问答贡献
用户名由3_15位
18
个答案
3
次被采纳
xiaorui
7
个答案
3
次被采纳
sakumisu
4
个答案
3
次被采纳
踩姑娘的小蘑菇
15
个答案
2
次被采纳
三世执戟
32
个答案
1
次被采纳
本月文章贡献
比特饼干
2
篇文章
6
次点赞
Z_Y
2
篇文章
5
次点赞
xusiwei1236
2
篇文章
3
次点赞
yinxiangxv
2
篇文章
3
次点赞
Alipay
2
篇文章
3
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部