MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

Cedric Wannaz
2

Prevent MATLAB from displaying full stack on error.

Cedric Wannaz
さんによって質問されました 2013 年 1 月 14 日
EDIT: see answer by Daniel, throwascaller () is what I needed.
Dear all,
Is there a way, when generating an error(), to limit MATLAB output to 'msgIdent' and 'msgString' without the stack information? The reason for this question is that I created a class, overloaded subsref/asgn, and each one of these methods calls yet another method that checks/updates subs. From my prospective, a user who uses invalid subs should only get the error Ident/String that I define, without it to be followed by the whole stack.
I could obviously print the information on stderr and manage the termination by myself, but then usual exceptions management mechanisms could not be used by external code..
Thank you and best regards,
Cedric

  0 件のコメント

サインイン to comment.

2 件の回答

回答者: Matt J
2013 年 1 月 14 日
編集済み: Matt J
2013 年 1 月 14 日
 採用された回答

Within SUBSREF/ASGN, you could put the call to the checks/updates inside a TRY...CATCH. Use the ME object returned by the CATCH to determine the error you want to display.
There's no way to get rid of the stack information preceding the call to subsref/subsasgn, I don't think. Only the info after it. I can't imagine why you'd want to get rid of the preceding stack info, though. The user will need that info to trace his/her error.

  1 件のコメント

Cedric Wannaz
2013 年 1 月 14 日
Thank you for your answer Matt, I think then that catching execptions at the subsasgn/ref level, as you mention, is the best that I can achieve. The reason I wanted to prevent the stack to be displayed is that I wanted the same behavior as with built-in classes/types, i.e:
>> x = true(2,2) ;
>> x(5,5)
Index exceeds matrix dimensions.
Here we don't have additional information like Error in true.subsref on line ..; it would even not be relevant to the user.

サインイン to comment.


回答者: Daniel Shub
2013 年 1 月 14 日

I think with careful use of try/catch and throwascaller you can achieve this. Just be careful since it makes debugging very difficult.

  1 件のコメント

Cedric Wannaz
2013 年 1 月 14 日
Thank you very much Daniel, this is exactly what I was looking for! I apologize for not being able to [Accept your answer] anymore as I had already done it.
Cedric

サインイン to comment.



Translated by