Is there a Try ... Catch or something in GDScript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FelipeRattu

I wanna know if the save file already exists, if not create one, if exists just preload it.

:bust_in_silhouette: Reply From: ATom 1

:bust_in_silhouette: Reply From: Calinou

Godot doesn’t feature exceptions like C++ or Java, but you don’t need them to safely read files. Just assign the result of methods that return an Error type to a variable and check whether the operation was successful using if err == OK.

I do need try-catch in gdscript. Situation: you read and perform multistep validation of some file. At the end with try-catch you can to execute “normal” procedure if validation succeed, if not you execute “exceptional”. Without try-catch you have to duplicate “exceptional” action for each validation step. Yes, you also can return some error on each step but what if all this happens inside of signal-handler and “emitter” doesn’t check for any errors.

yaroslav.s | 2020-10-18 17:45