フィルターのクリア

Confusing m-lint behaviour after catch statement

1 回表示 (過去 30 日間)
Chad Gilbert
Chad Gilbert 2011 年 12 月 7 日
I notice in my own code (and in some professional code, eg. the database toolbox) that it's frequently convenient to use a try/catch block that doesn't make use of the resulting MException object.
For example, if I want to try some "dangerous" statement (say, writing to an database with an unknown connection) but am willing to "just go along" if it fails, I would write something like:
try
cursor = exec(risky_connection, sql)
catch me %#ok
end
Given that m-lint complains about this by default, I presume there's a better construct to handle it... So what is it?

採用された回答

Titus Edelhofer
Titus Edelhofer 2011 年 12 月 7 日
Hi,
the code analyzer has some dilemma here: the reason he tells you about the exception object is to make the programmer aware of using the object is much better then the previous lasterr constructs. I guess the optimal solution would be: complain about missing identifier ME only if the user uses lasterr or similar in the catch block, otherwise not. For now he just always complains...
Since you know about the exception objects, you might just turn off the warning in the preferences or do like cyclist does, just suppress ...
Titus

その他の回答 (1 件)

the cyclist
the cyclist 2011 年 12 月 7 日
Have you read the detailed description of that particular m-lint warning? In a nutshell, it just says that best practice to use the exception identifier in the catch statement, etc.
Personally, I generally just suppress that m-lint warning. :-)
  1 件のコメント
Chad Gilbert
Chad Gilbert 2011 年 12 月 7 日
Thanks for responding. That's been my initial response to the message as well, however, the fact that m-lint is telling me one thing while I do another still suggests to me that there's a better way. M-lint messages have taught me many nice constructs over the years!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by