Using MATLAB® Tools to Handle COMSOL® Exceptions
When running a model that returns an error in MATLAB®, the execution of the script is automatically stopped. You can use MATLAB tools to handle exceptions and prevent the script from breaking. Use the try and catch MATLAB statements to offer alternatives to a failed model.
In a loop, for example, use the try and catch statements to continue to the next iteration. For automatic geometry or mesh generation you can use it to set the model properties with alternative values that circumvent the problem.