User`s guide
7 Libraries
M-Functions with No Return Values.
void <function-name>(< list _of_input_variables >);
M-FunctionswithatLeastOneReturnValue.
void <function-name>(i nt number_of_return_values,
<list_of_return_variables>, <list_of_input_variables>);
In this case, <list_of_input_variab les> represents a comma-separated
list of type
const mwArray& and <list_of_re turn_variables> represents
a comma-separated list of type
mwArray&. For example, in the libmatrix
library, the C++ interfaces to the addmatrix M-function is generated as:
void addmatrix(int nargout, mwArray& a , const mwArray& a1,
const mwArray& a2);
Error Handling
C++ interface functions handle errors during execution by throwing a C++
exception. Use the
mwException class for this purpose. Your ap p lication can
catch
mwExceptions and query the what() method to get the error m essage.
To correctly handle errors when calling the C++ interface functions, wrap
each call inside a
try-catch block.
try
{
...
(call function)
...
}
catch (const mwException& e)
{
...
(handle error)
...
}
The matrixdriver. cpp application illustrates the typical way to handle
errors when calling the C++ interface functions.
7-22