Exception handling in C++ code generated by Simulink Embedded Coder

9 visualizaciones (últimos 30 días)
Jose Mucino
Jose Mucino el 21 de Mzo. de 2022
Respondida: Varun el 28 de Dic. de 2023
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.

Respuestas (1)

Varun
Varun el 28 de Dic. de 2023
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:
Here are some general guidelines for handling exceptions in the context of code generated from Simulink models:
  1. 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.
  2. 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.
  3. Implement logging mechanisms in your generated code to capture information about errors, warnings, or unexpected conditions.
Hope it helps.

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by