Custom error messages with Class Object
이전 댓글 표시
Hello everyone,
I have a dynamic properties class I am creating to hold some experimental data. This code will be used by other users so I want to make any error messages associated with it more helpful. When you try to address a property not in the 'properties' list you get an error similar to below:
ex.Test = 1;
The error message I get reads:
"Unrecognized property 'Test' for class 'experimentStructureClass'."
I would like to modify the error message to that it directs people to used the ex.addprop() function to add a property.
Does anyone know how to access the error messages that arise from this?
Thanks a lot,
Michael
댓글 수: 2
Ameer Hamza
2020년 4월 9일
Tommy, Good example. This is exactly what the OP asked to do. I suggest adding this as an answer to this question.
Tommy
2020년 4월 9일
Absolutely - good call.
채택된 답변
추가 답변 (1개)
Anmol Dhiman
2020년 4월 9일
1 개 추천
Hi Michael,
The above functionality can be achieved using Exception Handling. You can modify the error displayed by catching the exception in try block and rewriting your own error message in the catch block.
For more information on how to do the above, you can refer to below documentation page.
If you face any issues in implementing it, let me know.
Thanks,
Anmol
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!