Error-handling mechanism (i.e. lack of exceptions/try/catch) in GDScript is badly documented #10542
Labels
area:class reference
Issues and PRs about the class reference, which should be addressed on the Godot engine repository
area:manual
Issues and PRs related to the Manual/Tutorials section of the documentation
content:new page
Issues and PRs related to creation of new documentation pages for new or undocumented features
enhancement
topic:gdscript
Your Godot version: v4.3.stable.flathub [77dcf97d8]
Issue description:
Although there are requests asking for GDScript to have a sort of Exception/try/catch mechanism, it has been denied:
godotengine/godot#3516 (comment)
Ok. Fine. I imagine there's a very good reason for it, so I won't go into whether or not I like this decision. I can see its point when the priority is efficiency.
But whatever is the alternative behavior is badly (euphemism to nearly-not-at-all) documented.
Firstly, there are methods that return
Error
, but there's quite some badly documented, e.g.:Array
append, and many others beingint
instead ofError
. If the int represents Error, why not fix the API? Isn't it compatible anyway, since it's an enum? Proper API is much better than having to read doc comments, because it's automatically checked and you get warnings appropriate to the expected fix. I assume it should be a non-breaking change, sorry if I misunderstand.Anyway, this isn't even the main issue.
What is really missing is the other cases, where it's not a
Error
return. The "intrinsic" errors (or whatever you call these).E.g. what happens on:
The docs for Array for example only say it pauses the project on the editor, but doesn't say what happens on runtime or when continuing:
And the editor debugger won't let me use "step into/over" to see what happens either, I can only use "continue". Why??
Just saying "it's designed to continue" without giving specifics is far from enough. Because there's many possible interpretations:
null
|zero|false|default (get) or ignore (set) and proceed normally?Imagine my surprise when I found out which one it is... (at least on the editor).
I bet most devs cannot guess what this is going to print!
Spoiler: output
URL to the documentation page (if already existing):
I don't know of other places where this info might be, sorry if I just didn't look properly, but I didn't find any obvious places.
TL;DR
I really believe there should be a dedicated page for Error handling in GDScript (or Core?) that covers what exactly happens in case of errors in all cases, specially when not involving
Error
. If this can trick even experienced devs with unexpected behavior, imagine the novice ones!Errors in Godot happen quite often, it's not a trivial subject, and I really think this subject deserves to have its own dedicated page, written by someone who understands the depths of Godot Core and GDScript.
The text was updated successfully, but these errors were encountered: