C++: How often should you check MStatus

19 views
Skip to first unread message

Kyle Burris

unread,
Jan 29, 2019, 9:31:52 AM1/29/19
to Python Programming for Autodesk Maya
I'm curious if anyone has any general guidelines on how frequently I should be checking MStatus for a production DG node or Deformer. Should I run CHECK_MSTATUS_AND_RETURN_IT every time a function can take a MStatus arg, or is that overkill? Should I only check when getting data out of the data block?

I realize this is a bit of a vague question, but I'm just wondering what your experience with it is.

Thanks
Kyle

Justin Israel

unread,
Jan 29, 2019, 1:36:42 PM1/29/19
to python_in...@googlegroups.com


On Wed, Jan 30, 2019, 3:31 AM Kyle Burris <kyleb...@gmail.com> wrote:
I'm curious if anyone has any general guidelines on how frequently I should be checking MStatus for a production DG node or Deformer. Should I run CHECK_MSTATUS_AND_RETURN_IT every time a function can take a MStatus arg, or is that overkill? Should I only check when getting data out of the data block?

I realize this is a bit of a vague question, but I'm just wondering what your experience with it is.

I will meet your vague question with a vague opinion :) 

You would use a CHECK_MSTATUS variant as often as you want to know when your call could have failed. As opposed to an exception-based error handling, MStatus is going to be returned/set when a function has defined error conditions. Skipping any of the checks is a good way to end up with undefined behavior and harder to solve bugs. It would be different if it were exception-based and your code could crash at any point, or if you could wrap entire blocks in a try/catch albeit with less context about the site of the error. 

If you can react to the error then you have the option of checking MFAIL. If the error wouldn't mean you need to stop your operations, then you can use CHECK_MSTATUS just for logging and debugging. Otherwise you have the other two to bail. It may seem verbose to have so much error checking but it's better than your code segfaulting further down, or claiming you have bad types or values. 


Thanks
Kyle

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/860d8717-81ff-4a9d-bce3-05d1905844ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kyle Burris

unread,
Jan 30, 2019, 5:10:20 PM1/30/19
to Python Programming for Autodesk Maya
Thanks Justin that's exactly the kind of info I was looking for.


On Tuesday, January 29, 2019 at 1:36:42 PM UTC-5, Justin Israel wrote:


On Wed, Jan 30, 2019, 3:31 AM Kyle Burris <kyleb...@gmail.com> wrote:
I'm curious if anyone has any general guidelines on how frequently I should be checking MStatus for a production DG node or Deformer. Should I run CHECK_MSTATUS_AND_RETURN_IT every time a function can take a MStatus arg, or is that overkill? Should I only check when getting data out of the data block?

I realize this is a bit of a vague question, but I'm just wondering what your experience with it is.

I will meet your vague question with a vague opinion :) 

You would use a CHECK_MSTATUS variant as often as you want to know when your call could have failed. As opposed to an exception-based error handling, MStatus is going to be returned/set when a function has defined error conditions. Skipping any of the checks is a good way to end up with undefined behavior and harder to solve bugs. It would be different if it were exception-based and your code could crash at any point, or if you could wrap entire blocks in a try/catch albeit with less context about the site of the error. 

If you can react to the error then you have the option of checking MFAIL. If the error wouldn't mean you need to stop your operations, then you can use CHECK_MSTATUS just for logging and debugging. Otherwise you have the other two to bail. It may seem verbose to have so much error checking but it's better than your code segfaulting further down, or claiming you have bad types or values. 


Thanks
Kyle

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages