subclassing MException

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

답변 (2개)

Daniel Shub
Daniel Shub 2012년 6월 18일

4 개 추천

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
Steffen
Steffen 2012년 6월 18일

1 개 추천

seems like the dependent property did the trick! works fine now :) thanks a lot!!

댓글 수: 1

Daniel Shub
Daniel Shub 2012년 6월 19일
Yet I don't get an upvote or an accepted answer :(

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Exception Handling에 대해 자세히 알아보기

제품

질문:

2012년 6월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by