Sambo wrote:if I call loadImage and don't give it a valid file name, it throws an error. I can fix it with a wrapper, but why doesn't it have one built in?
And no, I'm not intentionally giving it an invalid file name to see if I can break it. It's supposed to try to load an image as part of a loop. The images it can load depend on the images the user places in the folder.
Uhhh, that's not correct. Graphics.loadImage returns nil if you provide an invalid path.
However, Misc.resolveFile also returns nil if no relevant image could be found, and Graphics.loadImage WILL error if you try to load nil instead of an actual path. Which is sensible, because nil just means "non-existent data", of COURSE you'll get an error for trying to load with a path that doesn't exist (note that's distinct from "the file doesn't exist", in this case, the path
itself doesn't exist). This is intended and sensible system design - passing "nil" to this is ALWAYS an error case, so it's valid for it to error when this happens. It makes diagnosing problems a lot easier.
Just do a nil check on the result of Misc.resolveFile.