| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Builder NE |
| Contents | Index |
| Learn more about MATLAB Builder NE |
As with managed code, any errors that occur during execution of an M-function or during data conversion are signaled by a standard .NET exception.
Like any other .NET application, an application that calls a method generated by the MATLAB Builder NE product can handle errors by either
Catching and handling the exception locally
Allowing the calling method to catch it
Here are examples for each way of handling errors.
In the GetPrimes example the method itself handles the exception.
public double[] GetPrimes(int n)
{
MWArray primes= null;
MyPrimesClass myPrimesClass= null;
try
{
myPrimesClass= new MyPrimesClass();
primes= myPrimesClass.myprimes((double)n);
return (double[])(MWNumericArray)primes).
ToVector(MWArrayComponent.Real);
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex);
return new double[0];
}
}
In the next example, the method that calls myprimes does not catch the exception. Instead, its calling method (that is, the method that calls the method that calls myprimes) handles the exception.
public double[] GetPrimes(int n)
{
MWArray primes= null;
MyPrimesClass myPrimesClass= null;
try
{
myPrimesClass= new MyPrimesClass();
primes= myPrimesClass.myprimes((double)n);
return (double[])(MWNumericArray)primes).
ToVector(MWArrayComponent.Real);
}
catch (Exception e)
{
throw;
}
}
![]() | Using MATLAB API Functions in a C# Program | Overriding Default CTF Archive Embedding for Components Using the MCR Component Cache | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |