Purpose of error identifiers
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hau Kit Yong
el 11 de Mayo de 2019
Comentada: Xingwang Yong
el 22 de Mayo de 2022
I am curious about the practical uses of error identifiers, for example the 'identifier' property in MException objects.
From the documentation (https://uk.mathworks.com/help/matlab/matlab_prog/capture-information-about-errors.html#bq9tdlq-1), I gather that the identifiers are tags for error statements that make them unique. The docs go on to say that the the identifiers can help better identify the error source and also be used to control the error display. The examples that follow however just show how identifiers are created and extracted, so I struggle to see how it can be useful over say, just returning the 'message' property itself.
Why make error statements unique? What is the utility of the identifiers?
0 comentarios
Respuesta aceptada
Walter Roberson
el 11 de Mayo de 2019
It is common for the exact spelling and phrasing and formatting of error messages to evolve. When you go to try/catch an error it is inconvenient to have to update all of the various places that have a particular exact spelling and phrasing to be able to match the changes. Instead it is more convenient to use a token that does not change to represent the error for try/catch purposes, permitting the spelling and phrasing to be changed in just one place.
In particular, using a token to stand in is a practical necessity when you make the program multilingual. When you use a token (error identifier) you can try/catch on just one short representation of the condition and then program in "message catalogs" that hold the translation to a variety of human languages.
4 comentarios
Walter Roberson
el 22 de Mayo de 2022
See https://www.mathworks.com/matlabcentral/answers/373512-how-can-i-open-message-key-catalog#answer_296850 for information on how MATLAB searches for the identifier.
I do not know if there is a better way to create your own catalog, but the implication is that you could create a matlabroot resources/MyToolbox folder to put the catalogs into.
Xingwang Yong
el 22 de Mayo de 2022
@Walter Roberson Thanks, Walter. I've read that answer before asking here. I'll try it.
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!