开发者

Handling missing resources

开发者 https://www.devze.com 2022-12-28 17:57 出处:网络
I\'ve just found myself in situation where I needed to handle exception I\'ll probably never get, so out of curiosity, let\'s do a small poll.

I've just found myself in situation where I needed to handle exception I'll probably never get, so out of curiosity, let's do a small poll.

  1. Do you val开发者_StackOverflow中文版idate the presence of resources in your programs? I mean, those resources which are installed with your program, like icons, images and similar. Generally, if those are missing, either your install didn't do its job, or the user randomly deleted files in your app.

  2. If you do validate the presence, what do you do when the files are not there?

Of course, for web apps, you'll have nice 404 page or broken link, but what about the rest? Fail early, yes, but leave handling failures to your compiler, or what?


In Python, many folks rely on simple exception handling for this kind of thing. We might wrap an application in a Big-Old-Try-Block that reports "serious problems" for unhandleable exceptions like this and tries to clean up and exit gracefully.

It's hardly worth checking deeply in advance.

If it's even possible for the user to get to some super delicate and precious part of the application and the app dies undoing hours (or years) of work, then you should rethink that use case to create a more robust scenario where a crash is not so destructive.


Graceful Degradation:

Handling missing resources

... but no, in a lot of cases it doesn't really matter if resources are missing, that's violating the structural integrity of the program. In the case in my picture above, it's a video game where resources are loaded over the net, and sometimes (I think?) the server doesn't supply the textures needed so they are displayed as pink and black checkers. In that case it makes a bit of sense.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号