eugeneloza / decoherence

Project moved to https://gitlab.com/EugeneLoza/decoherence
GNU General Public License v3.0
10 stars 7 forks source link

Test trying to read an inexisting field in XML file #592

Open eugeneloza opened 6 years ago

eugeneloza commented 6 years ago

So that load procedure will be robust even if data structure changes. Especially important for configuration stuff or when loading a previous-version savegames.

eugeneloza commented 6 years ago

afair it will give an exception. So either catch the exception or use "reader" with default value. It's better to have the exception (not just hidden in a log file) for testing, however, some values can be safely reset to default in case of exception (like game configuration). Not yet sure how to implement this feature correctly.

Feels like this is better:

try
  Read
except
  if RaiseReadExceptions then 
    Raise Exception.Create...
end;

as it enables turn on/off exceptions to convert old data. However, when actually will exception raise? It looks like it will stop reading any further as soon as it encounters invalid field. Add this try/except to every read procedure? Looks plausible, reliable and efficient. This way I can make "import from previous version" even user-side (e.g. so that user can load a savegame which is not fully compatible with the new game version).