Global exception handling in a GUI class

Hi,
I have a class that represents a GUI window and want to display any kind of exception that occurs in any class method as a errordlg (as console output ist not useful when using a gui).
  • Is there a convenient way to redirect all exception-message-strings to the function errordlg()?
  • This should especially include all errors that occur within any class method (like a call to obj.methodXY())
  • It is desireable to catch also other errors (like wrong use of obj(..))
I have already tried overloading B=subsref(A,S), but this causes vast problems when methods with/without input-/output-arguments are called.

답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 9월 17일
편집: Sean de Wolski 2013년 9월 17일

0 개 추천

I don't think there is a way to redirect from standard error to error dialog. You'll have to catch the MException and then throw the error dialog from there. This could be packaged as a function to make it reusable.

댓글 수: 2

Yes I have assumed that there is no general function or the like to do this.
Of course I could place try-catch-statements in every single class method to redirect the error to an error dialog. But I want to avoid to do this for every method.
I would like to have something similar to the approach in the following piece of code: the subsref() method does exactly the same as the builtin-subsref method but for redirecting every exception to an error dialog:
class classX < handle
methods
function method1(obj, arg1);
function out1 = method2(obj);
function varargout = subsref(obj, S)
try
varargout = builtin('subsref', obj, S);
catch ex
errordlg(ex.message, ex.identifier);
end function obj = classX()
% constructor code...
endend
end
In this code, the subsref method doesn't perform well with different types of methods.
Sean de Wolski
Sean de Wolski 2013년 9월 17일
I guess I don't understand how subsref would be called from a user using the figure/GUI/app.
Wouldn't whatever the user is doing be safeguarded against at that level? How are they going to use subsref?

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

카테고리

제품

질문:

2013년 9월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by