App designer - custom global error handling
Show older comments
I am trying to add general custom error handling to App Designer application. One of the use cases is e.g. when an unhandled error would trigger a pop-up window with that error. I see this useful to me for a compiled application without command line.
If there is an error in any callback, AppManagementService instance will catch it in the tryCallback method. This method will also notify listeners using fireCallbackErroredEvent.
I naive way to try to listen that callback could be AppManagementService.instance() since it is referencing to a unique singleton.
function startupFcn(app)
service = appdesigner.internal.service.AppManagementService.instance();
addlistener(service, 'CallbackErrored', @app.displayErrorDialog);
end
However, it is not possible to connect to the notifier since access is restricted only to following to classes:
events (ListenAccess = {?appdesigner.internal.appalert.AppAlertController; ...
?appdesigner.internal.service.WebAppRunner})
% This event is fired when there's an exception or error happening
% in the app's callback or startup function
CallbackErrored
I am maybe overengineering the general custom error handling and I am not aware of some functionality in App Designer.
Do you have any suggestions how to approach this problem? Any advice is appreciated.
Edit:
I have created following class inherited from AppAlertController and this class is able to listen CallbackErrored from AppManagementService. It is working in classic Matlab IDE, but not after compilation to standalone app. It seems that supercalss is not being is imported to Matlab runtime.
classdef AppAllertErrorHandler < appdesigner.internal.appalert.AppAlertController
methods
function obj = AppAllertErrorHandler()
service = appdesigner.internal.service.AppManagementService.instance();
obj.CallbackErroredListener = addlistener(service, 'CallbackErrored', @obj.displayErrorDialog);
end
end
methods(Access = protected)
function doSendErrorAlertToClient(obj, appException)
% Empty implementation of superclass abstract method
end
end
methods(Access = private)
function displayErrorDialog(obj, event, source)
% display dialog
Error = source.Exception;
msg = sprintf('Unhandled exception \nIdentifier: %s\nMessage: %s in file %s at line %d ', ...
Error.identifier, Error.message, Error.stack(1).name, Error.stack(1).line);
msgbox(msg, 'Unhandled exception');
end
end
end
Following error is obtained after compilation
testApp.exe
Error using AppAllertErrorHandler
The specified superclass 'appdesigner.internal.appalert.AppAlertController' contains a parse error, cannot be found on MATLAB's search path, or is shadowed by another file with the same name.
Error in testApp/startupFcn (line 18)
Error in appdesigner.internal.service.AppManagementService/tryCallback (line 371)
Error in appdesigner.internal.service.AppManagementService/runStartupFcn (line 153)
Error in matlab.apps.AppBase/runStartupFcn (line 43)
Error in testApp (line 61)
MATLAB:class:InvalidSuperClass
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!