A common problem with optimization of machines is that occasionally, some of the variable combinations will not be geometrically feasible. For example, if magnet angle is being parameterized in an IPMSM, it might be that at some point, the magnet skews so much that it juts out of the rotor. Generally, it is possible to define the limits of the variables, but since I am playing with a global optimization, there are 5 attributes that can vary and the limits of each are interdependent, which makes it impossible within the current framework to account for all of the cases that will generate a non-feasible geometry. If I run an optimization, it generally stops sometime in the middle of the night, when it encounters one of these non feasible geometries and I have to start over, which is frustrating. One way to circumvent this is to use a script and calculate previously if a certain configuration is feasible, but this is time consuming and I am not great at VB (I have done this in MATLAB). The easier way (still using VB scripts) would be to run an optimization and to "catch" an error whenever it occurs within VB, cancel the analysis of this erroneous case and move on to the next case. Something like this is really easy to do in MATLAB. Does anyone have sample code or a possible solution to how the error can be caught during optimization? I can't find any error handling guides in the native help files.