- Feature Articles
-
CodeSOD
- Most Recent Articles
- Brushing Up
- Irritants Make Perls
- Crossly Joined
- My Identification
- Mr Number
- intint
- Empty Reasoning
- Zero Competence
-
Error'd
- Most Recent Articles
- Not Impossible
- Monkeys
- Killing Time
- Hypersensitive
- Infallabella
- Doubled Daniel
- It Figures
- Three Little Nyms
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Assuming that the logic of the code is correct, which it probably is the only sin here is not wanting to use nested try / catch blocks with catch actually doing what it's supposed to. But to be fair there, we are all so used to catch being used only to log and rethrow that it is understandable if unfortunate that someone might feel anxiety about writing "productive" code in a catch block.
Edit Admin
One possibility is that the Framework function sometimes returns null and sometimes throws an exception. Which would make the framework TRWTF.
Edit Admin
The only reason I can think of for the two calls to get the image is the framework might be doing something that the first SHOULD work, but maybe too small of a timeout value makes the first call fail like 90% of the time, and the second call happens to use the cached data created by the first call, which, if allowed to run 10ms more, would allow the image to be received.
Edit Admin
They first try to fetch a localized image, if that fails they try to get a default one and if that fails they just return a white Brush. The way I see it the exception isn't captured because it isn't relevant and the code is implemented with the implication that some or all requested images will be missing.
The part that actually caught my attention was the "BorderChannelGroupBrush" variable which looks like it was an instance o maybe a static made local, probably as a result of a change in requirements.
Edit Admin
I was thinking the same. If "boomerang code" is bad, "boomerang code in catch blocks" is worse.
Edit Admin
At least it only took until the fourth post for someone to remark that it isn't two attempts to fetch the same image, but one for the localised image (
frobble-en.jpg
) and one for the non-localised image (frobble.jpg
).The thing that makes my teeth itch, however, is that there is no way to see at runtime (when compiled in debug mode, naturally) that we failed to fetch both images.
Even if it's just the equivalent of an
ifdef
'ed call toOutputDebugString
in the catch blocks, it would be nice to have some indication that it failed, and even better, why.Addendum 2025-01-15 12:11: Note: the indication is to distinguish "we downloaded a white image" from "we failed totally to download an image"
Edit Admin
I think this one is actually reflecting for the real WTF. First off, there's nothing really wrong with getting the index of the extension, especially since this doesn't seem to be some random images but some assets that get loaded into this obvious ancient WinForm app from a remote server.
However
ServicePageImageUrlOnContentServer
is the weirdest method name I have ever read. It's just a collection of nouns. So this puts a lot into perspective and I think the main issue might even be found there. I guess this methods just doesn't do proper exception handling, fails with improper exceptions, falls through with null, is not deterministic, all the fun stuff.So yeah, this code will not get any beauty points for sure but heck would it be interesting to get a peek into this weird method.
Addendum 2025-01-15 12:14: WPF app, not WinForm obviously.
Edit Admin
I try to avoid doing that because an uncaught exception in a catch block terminates the program immediately.