How to use error handling with tcpclient in R2021b?
I am using tcpclient to communicate with a remote server, and when data is received I want to process that data using a callback. However, if any error occurs in the callback, that error is not reported to the command line. Here’s a minimum working example:
echotcpip(‘on’,7841); %Just a random port
obj = tcpclient(‘localhost’,7841);
obj.configureTerminator(‘CR/LF’);
obj.configureCallback(‘terminator’,@(~,~) error(‘An error!’));
obj.writeline(‘Hello’);
When data is received, I expect an error to be thrown, but instead nothing happens. If I replace the callback with something that doesn’t throw an error:
obj.configureCallback(‘terminator’,@(~,~) disp(‘No errors here’));
obj.writeline(‘Hello’);
the line "No errors here" is printed on the command line, as expected.
How do I get the errors in the callback to show up? The ErrorOccurredFcn appears to only apply to internal errors in the tcpclient class, and not to errors in the callback function.
This is a problem in R2021b, but not in R2022a (and probably in later versions), but if there is a solution that does not involve upgrading to the next release, that would be great. I’ve had severe performance issues with tcpclient when switching versions, and I’d like to avoid the risk of dealing with that if it isn’t necessary.I am using tcpclient to communicate with a remote server, and when data is received I want to process that data using a callback. However, if any error occurs in the callback, that error is not reported to the command line. Here’s a minimum working example:
echotcpip(‘on’,7841); %Just a random port
obj = tcpclient(‘localhost’,7841);
obj.configureTerminator(‘CR/LF’);
obj.configureCallback(‘terminator’,@(~,~) error(‘An error!’));
obj.writeline(‘Hello’);
When data is received, I expect an error to be thrown, but instead nothing happens. If I replace the callback with something that doesn’t throw an error:
obj.configureCallback(‘terminator’,@(~,~) disp(‘No errors here’));
obj.writeline(‘Hello’);
the line "No errors here" is printed on the command line, as expected.
How do I get the errors in the callback to show up? The ErrorOccurredFcn appears to only apply to internal errors in the tcpclient class, and not to errors in the callback function.
This is a problem in R2021b, but not in R2022a (and probably in later versions), but if there is a solution that does not involve upgrading to the next release, that would be great. I’ve had severe performance issues with tcpclient when switching versions, and I’d like to avoid the risk of dealing with that if it isn’t necessary. I am using tcpclient to communicate with a remote server, and when data is received I want to process that data using a callback. However, if any error occurs in the callback, that error is not reported to the command line. Here’s a minimum working example:
echotcpip(‘on’,7841); %Just a random port
obj = tcpclient(‘localhost’,7841);
obj.configureTerminator(‘CR/LF’);
obj.configureCallback(‘terminator’,@(~,~) error(‘An error!’));
obj.writeline(‘Hello’);
When data is received, I expect an error to be thrown, but instead nothing happens. If I replace the callback with something that doesn’t throw an error:
obj.configureCallback(‘terminator’,@(~,~) disp(‘No errors here’));
obj.writeline(‘Hello’);
the line "No errors here" is printed on the command line, as expected.
How do I get the errors in the callback to show up? The ErrorOccurredFcn appears to only apply to internal errors in the tcpclient class, and not to errors in the callback function.
This is a problem in R2021b, but not in R2022a (and probably in later versions), but if there is a solution that does not involve upgrading to the next release, that would be great. I’ve had severe performance issues with tcpclient when switching versions, and I’d like to avoid the risk of dealing with that if it isn’t necessary. tcpclient, error MATLAB Answers — New Questions