+1 vote

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

in Engine by (70 points)

2 Answers

+2 votes

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.

by (12,649 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.