There are many ways to generate a runtime error in GDScript: calling methods on nulls, calling non-existent methods, asserts, passing wrong arguments, etc.

Since GDScript does not have things like try-catch, what happens when an error occurs (in debug and release mode)? Will it just skip one line and keep going? Or skip the entire function the error occurred in? Or just crush the entire game? I'm asking this because I can't find a clear statement on errors in the document, and I feel unsafe writing code without knowing how errors work.

Thanks in advance.

It's pretty hard to crash a Godot game when you are playing in release mode. Someone on Reddit was trying to do this (to test something) and I tried a lot of things to eventually get it to crash. Divide by zero is one case where the app will hard crash. However, most things result in a script error that will fail silently. For example, calling methods on null objects, accessing an out of bounds index on an array, sending nonsense parameters to functions, etc. are all no problem. Of course, it doesn't work, but it doesn't do anything bad either. However, while you are testing in the editor, these are considered crashes and you have to fix them (which makes sense).

@cybereality said: However, most things result in a script error that will fail silently. For example, calling methods on null objects, accessing an out of bounds index on an array, sending nonsense parameters to functions, etc. are all no problem. Of course, it doesn't work, but it doesn't do anything bad either.

Can I assume "fail silently" means skip whatever line that gives the error and continues running? So for example I have a script:

var first_var = 0
var second_var = 0

func my_func(para1, para2):
	first_var = some_object.some_method(para1, para2)  # "some_method" gives an error
	second_var = 2

After my_func is called, first_var will be left unmodified, and second_var will be assigned value 2, is this correct?

Ok, I did some experiments and now I get it. When an error occurs, the code will push an error to the debugger and just cause whatever function it is in to return null. Any code after the error within the function will not be executed.

Maybe this should be added to the tutorials. Simply saying there is no exception handling in GDScript is confusing for people who are familiar with exception handling in other languages.

The function will fail silently, but the results will probably be invalid (such as null). So checking for null variables is still a good idea. I didn't know about the rest of the function not being executed, but that does make sense.

a year later