How do I handle BOTH MException and MSLException
Mostrar comentarios más antiguos
I am very experienced with exceptions in C++ so the concept is nothing new to me. However. implementing it in the Mathworks world is. I have a handler function that I want to accept a generic exception object and inside the handler determine which exception ofject it is and act based on that determination. "isa" doesn't work since it returns a 1 regardless if I check it for MSLException or MException.
Bottom line, if I could figure out a way to determine if an exception object was either a MSLException or a MException then I can take it from there.
Any ideas?
Respuesta aceptada
Más respuestas (1)
Sean de Wolski
el 16 de Mzo. de 2015
Editada: Sean de Wolski
el 16 de Mzo. de 2015
MSLException inherits from MException so isa will return true for both. A regular MException is not necessary an MLSException, so test this:
kdlsjfajfe % errors
ME = MException.last;
isa(ME,'MSLException')
2 comentarios
Virgil Bell
el 16 de Mzo. de 2015
Sean de Wolski
el 16 de Mzo. de 2015
Editada: Sean de Wolski
el 16 de Mzo. de 2015
That was just for me to create one for you.
In reality
try
% Whatever you're doing
catch ME
if(isa(ME,'MSLException'))
% it is
else
% it's a regular MException
end
end
Categorías
Más información sobre Function-Based Unit Tests en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!