23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Message Identifiers<br />

are a particular product or toolbox name, such as <strong>MATLAB</strong> or Control, or<br />

perhaps the name of your company, such as TechCorp in the example above.<br />

You can also use this field to specify a multilevel component. The statement<br />

below has a three-level component followed by a mnemonic label:<br />

TechCorp:TestEquipDiv:Waveform:obsoleteSyntax<br />

Onepurposeofthecomponentfieldistoenableyoutoguaranteethe<br />

uniqueness of each identifier. Thus, while <strong>MATLAB</strong> uses the identifier<br />

<strong>MATLAB</strong>:divideByZero for its 'Divide by zero' warning, you could reuse the<br />

divideByZero mnemonic by using your own unique component. For example,<br />

warning('TechCorp:divideByZero', ...<br />

'A sprocket value was divided by zero.')<br />

Mnemonic Field<br />

The mnemonic field is a string normally used as a tag relating to the particular<br />

message. For example, when reporting an error resulting from the use<br />

of ambiguous syntax, a mnemonic such as ambiguousSyntax might be<br />

appropriate:<br />

error('<strong>MATLAB</strong>:ambiguousSyntax', ...<br />

'Syntax %s could be ambiguous.\n', inputstr)<br />

Using Message Identifiers with lasterror<br />

Oneuseofmessageidentifiersistoenablethelasterror and lasterr<br />

functions to better identify the source of an error. These functions return<br />

a message identifier, and you can use the combination of component and<br />

mnemonic parts of that identifier to identify both a broad category of errors<br />

and a specific instance within that category, respectively.<br />

The first step in using this feature is to determine which of your error<br />

messages need this type of identification and then tag each with an identifier.<br />

You do this by specifying a message identifier argument (msg_id, below)<br />

along with the error message in your calls to error. Either form shown<br />

below is acceptable. The latter form uses formatting conversion characters as<br />

described in “Formatted Message Strings” on page 8-14.<br />

8-11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!