subclassing MException
7 次查看(过去 30 天)
显示 更早的评论
Hi there,
is it possible to subclass MException?? I'm trying to mock a third party software and therefore i need an exception object with the property 'ExceptionObject', so that i can run some code like this:
try
%some commands
catch exception
disp(exception.ExceptionObject.Message);
end
when i just subclass MException, the creation of the object fails with the error message 'not enough input arguments'. I'm using two strings(identifier & message) as input arguments, and creating a 'normal' MException object with these two arguments works fine.
Does anybody know where this error could come from, or any other way to create a custom exception object?
cheers, steffen
0 个评论
回答(2 个)
Daniel Shub
2012-6-18
There are a lot of places you can go wrong, and without the code, it is hard to guess...
classdef testclass < MException
properties (Dependent = true)
ExceptionObject;
end
methods
function obj = testclass(varargin)
obj = obj@MException(varargin{:});
end
function val = get.ExceptionObject(obj)
val.message = obj.message;
end
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Error Handling 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!