Get matlab error and warning text in C#

1 view (last 30 days)
As the title states. I am looking for a way to retrieve both warning and error message when Matlab throws an exception while running in C#. Any input would be appreciated as all I am currently able to produce are the normal warnings.
The warnings mentioned above are the ones appearing in orange text inside Matlabs command window
  1 Comment
Rebecca Krosnick
Rebecca Krosnick on 24 Dec 2015
Did you compile your MATLAB code into a .NET assembly and now you are using the .NET assembly in a C# application? Alternatively, are you using MATLAB Engine to call MATLAB functions from your C# application?
My understanding is that you are using the MATLAB deployed .NET assembly in a C# application. In this case, I believe the exception object generated in the C# try/catch should include a message property that contains the error message. This exception object will not contain warning messages, though, since a "catch" will not be triggered by a warning.
In order to capture warning messages, you can use the "lastwarn" function: http://www.mathworks.com/help/matlab/ref/lastwarn.html
If you expect a warning to have occurred after a particular function call, you can call the "lastwarn" function to capture the warning message.
I do not think there is a way to specifically listen for warnings, however.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!