MATLAB Application Program Interface
  Go to function:
    Search    Help Desk 
mxAssert

Check assertion value for debugging purposes

C Syntax

Arguments

expr
  Value of assertion.

error_message
  Description of why assertion failed.

Description

Similar to the ANSI C assert() macro, mxAssert checks the value of an assertion, and continues execution only if the assertion holds. If expr evaluates to true, mxAssert does nothing. If expr is false, mxAssert prints an error to the MATLAB Command Window consisting of the failed assertion's expression, the file name and line number where the failed assertion occurred, and the error_message string. The error_message string allows you to specify a better description of why the assertion failed. Use an empty string if you don't want a description to follow the failed assertion message.

After a failed assertion, control returns to the MATLAB command line.

Note that the MEX script turns off these assertions when building optimized MEX-functions, so you should use this for debugging purposes only.

Assertions are a way of maintaining internal consistency of logic. Use them to keep yourself from misusing your own code and to prevent logical errors from propagating before they are caught; you do not use assertions to prevent users of your code from misusing it.

Assertions can be taken out of your code by the C preprocessor. So, you can use these checks during development and then remove them when the code works properly, giving you the ability to use them for troubleshooting during development without slowing down the final product.



[ Previous | Help Desk | Next ]