Replies: 7 comments 17 replies
-
Could you show what kind error handling code you are currently writing and what kind of code you would like to write? |
Beta Was this translation helpful? Give feedback.
-
I agree with your position, even though I haven't considered using signals for error handling (sounds kinda awkward). What I am doing right now with my error handling is to log (and assert) and hope for the best. Kinda unnerving. That is certainly not what writing robust code looks like. Unfortunately the chances for such a change are about 0. GDScript wouldn't just need exception support. It would also need support for writing exception-safe code. And it would have to be done going from 3.x to 4.0, not 4.x. We certainly don't want more API breaking going from 4.0 to 4.1. Since we are already on the 3rd alpha for 4.0 time is running out on that. Additionally at leat a part of the core teams seems to be kinda hostile to exceptions (other than some third-party code and some C# stuff the Godot code base doesn't seem to use a single exception). And then there is this statement from the official documentation:
Who ever wrote that clearly doesn't understand exceptions, since it is the other way around. Using exceptions properly allows you to recover from errors far more easily and more reliably than other methods. |
Beta Was this translation helpful? Give feedback.
-
I don't like using exceptions for error handling. Maybe I have seen too much code where error handling using exceptions is just wrapping try-catch around code and ignoring the error. Exceptions have their use, but I think there are better alternatives for error handling. Maybe GDScript could have Go-like error handling, athough it would need some big changes too. Functions should be able to return multiple return values. A new type, error, would be needed. Function would return the error as a last return value. The caller should then always check if error was returned. Code would look something like this: func do_something(a: int) -> int, error:
if a < 100:
return a + 1, null # maybe return null by default, if second return value is not given
else:
return 0, "parameter too large"
func test():
var result: int
var err: error
result, err = do_something(42)
if err != null:
# handle error |
Beta Was this translation helpful? Give feedback.
-
I understand the interest on exceptions by means of "writing software". (for developing tools/other software) But for gamedev it isn't really desirable, its better to use system of error codes, as Godot's main concern is to develop games. Not sure of how viable is to implement exceptions for GDScript; What problem you have with using error codes? |
Beta Was this translation helpful? Give feedback.
-
PS: A proposal was written on the subject a while ago: #3194 |
Beta Was this translation helpful? Give feedback.
-
As a very poor excuse to bump this, I would like to add not having a proper exception handling means static functions are nerfed since they either return error value or result. you cannot i.e. make static functions that returns a string and can error. |
Beta Was this translation helpful? Give feedback.
-
After reviewing this article.. The problem of error handling couldn't be solved by combining the use of error codes and unit tests? |
Beta Was this translation helpful? Give feedback.
-
This is really bothering me as someone who occasionally write singleton API stuff in Godot.
As of currently, there are no way to throw errors and the most you can do is pushing error messages to the log, nothing more. The code does not stop execution and the only way for the caller to be able to acknowledge and do something with errors is to use signals, which works but is an annoying workaround.
Most programming languages(C#, Python, Lua, etc.) have a complete error system where you can throw errors, and they will:
pcall
&xpcall
, etc.)I know this addition will require changing a lot of the engine API and can only be implemented in 4 (since this may be a breaking change) but it should still greatly help with making API interfaces in GDScript where throwing error is a very useful thing.
Beta Was this translation helpful? Give feedback.
All reactions