Yes, I know why Godot Devs don’t include a try catch in GDscript, because your just to “Not supposed to have bugs” I get that. There are some circumstances in which bugs are inevitable, unless you want to spend till the heat death of the universe finding fixing bugs and never adding new features.
Take for instance A project I have been working on: You can upload a package with custom JSON files, and it generates a game out of that. If the user uploads a JSON file with faulty syntax, I have tried to implement safeguards to prevent the game from crashing when it loads it, and just display an error message, but I CAN’T account for EVERY little thing the user might do to cause the system to fail, I NEED a try catch to prevent the game from just abruptly freezing when the user does something weird on their JSON file that I didn’t account for.
Will Try catch ever be added to Godot?? I’m a little frustrated by the fact that the devs don’t understand that in some circumstances, bugs are inevitable, and just trying to ignore the solution by making excuses isn’t the solution.
The file loader and JSON parser have return codes which are relatively easy to process, and when you’re working with the loaded data you can use .has() to wrap accesses, or use .get() with a default. It’s not that hard to live without try/catch if you want to, and your flow control will be more comprehensible without a bunch of implicit goto lines scattered around.
Not having a try-catch is a deliberate design choice, for multiple reasons.
Saying that “you’re not supposed to have bugs” is not exactly a great way to look at it either.
In web development and similar areas, having a try-catch makes sense, since you need to keep the application alive no matter what happens, since you shouldn’t have your server crash no matter what. But game development is different, and if you reached a state where something goes horribly wrong, it’s generally a REALLY bad idea to try and keep the game alive, since if you had a hard exception thrown somewhere, it’s very likely that there are already bigger problems and corruptions going on in the game, and keeping things alive will lead to a really glitchy experience.
In your example, I believe you can use the .get() function instead of something like json[“field”], as @hexgrid already mentioned.
And to answer your last question, as far as I know, godot has a “fail fast” philosophy, so it’s very unlikely that try-catch will be added, especially considering that it costs quite a bit of performance to implement.