- Use MATLAB assert and error statements within your Simulink model to check for conditions that should not occur during simulation. These can be translated into explicit error checks in the generated code.
- Instead of using try/catch for error handling, consider using traditional C error-handling mechanisms such as return codes or global variables to indicate errors.
- Implement logging mechanisms in your generated code to capture information about errors, warnings, or unexpected conditions.
Exception handling in C++ code generated by Simulink Embedded Coder
9 次查看(过去 30 天)
显示 更早的评论
What is the recommended way to throw, catch, and handle exceptions for utility functions used in simulink models from which C++ code is then generated using Embedded Coder? I couldn't get a clear answer from the docs. The closest thing I found was this..
Which mentions something about std::runtime_error, but it is unclear if I can throw custom errors in the generated code the same way I would if I was operating inside matlab. Furthermore, try/catch are supposedly not supported for code generation, so I'm not sure how I would even handle the error if I could throw it.
0 个评论
回答(1 个)
Varun
2023-12-28
Hi Jose,
I understand that you want to throw custom errors in the generated code in the same way as it was operating inside the MATLAB.
Exception handling is unfortunately not yet supported in MATLAB/ Embedded Coder as of MATLAB R2023b.
You can refer to similar question asked on this forum, answered by the staff:
https://www.mathworks.com/matlabcentral/answers/1732705-error-recovery-try-catch-for-code-generation
Here are some general guidelines for handling exceptions in the context of code generated from Simulink models:
Hope it helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!