Catching messages displayed on the command window

조회 수: 11 (최근 30일)
Ajpaezm
Ajpaezm 2020년 2월 17일
댓글: Monika Phadnis 2020년 2월 26일
When I try to connect to another program, and the user has not logged in, it starts printing these messages:
I know how to get the ones highlighted in red, using a try-catch routine. But how can I search for the ones in black? The ones that say "failed to connect using..."?
Is there a routine I can use to raise a flag when this events are registered on the command window of Matlab?
Thanks for your help!

답변 (1개)

Monika Phadnis
Monika Phadnis 2020년 2월 18일
These links may help to get the exception message displayed :
  1. There is a function "getReport" which can be used to get the message displayed for an exception. Here's the link to the doc : https://www.mathworks.com/help/matlab/ref/mexception.getreport.html
  2. You can also log the command window text to a file using "diary" command. Here's the link to the doc : https://www.mathworks.com/help/matlab/ref/diary.html
Hope this helps.
  댓글 수: 2
Ajpaezm
Ajpaezm 2020년 2월 25일
Thank you Monika. To use diary I must wait until the execution of the command I'm recording has finished right?
This can be an inconvinience, as what I would like to do is to get messages as they come up right away and compare them to a specific string, which will be my trigger to do other things inside the program.
Monika Phadnis
Monika Phadnis 2020년 2월 26일
Try using the getReport function. You can put the code in try catch blocks and store the exception messages in variables.
A small example could be:
try
surf
catch exception
errorMsg = getReport(exception)
end
Here, errorMsg will have the error text stored.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by