{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibwximbz2wbstl4nak43c77hea7wf34neeezzjqdxiu5ag2c2yihi",
"uri": "at://did:plc:vyjlfm46mfv6u4vjp6qtrfx2/app.bsky.feed.post/3mkq7yipff522"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreidg2k33tiuupnstmiowh7hyyvtsbe3gyhfygiytrzynysnhoctrxi"
},
"mimeType": "image/jpeg",
"size": 81260
},
"path": "/articles/cancel-catch",
"publishedAt": "2026-04-30T06:30:00.000Z",
"site": "https://thedailywtf.com",
"tags": [
"CodeSOD",
"Download Free Guide Now!"
],
"textContent": "\"This WTF is in Matlab\" almost feels like cheating. At one place I worked, somebody's job was struggling through a mountain of Matlab code and porting it into C. \"This Matlab code looks like it was written by an alien,\" also doesn't really get much traction- _all_ Matlab code looks like it was written by an alien. This falls into the realm of \"Researchers use Matlab, researchers may be very smart about their domain, but generally don't know the first thing about writing maintainable code, because that's not their job.\"\n\nBut let's take a look at some MatLab **Carl W** found:\n\n\n try\n if (~isempty(fieldnames(bigStruct)) && isfield(bigStruct,'pathName'))\n [FileName, PathName] = uigetfile(bigStruct.pathName);\n else\n [FileName, PathName] = uigetfile(lastPath); %lastPath holds previous path\n end\n catch\n bigStruct = struct;\n end\n\n\nThe `uigetfile` function opens a file dialog box. When the user selects a file, `FileName` holds the filename, `PathName` holds the containing path. If the user doesn't select a valid file, or clicks \"Cancel\", both of those variables get set to `0`. It's then up to the caller to check the return value and decide what happens next.\n\nWhich is not what happens here, obviously. The developer responsible seems to believe that it maybe throws an exception? And they can just catch it? Carl's best guess is that this is a \"weird\" way to catch the cancel button. But it does mean that `FileName` and `PathName` get set to `0`, and those zeros propagate until something finally tries to open those files, at which point everything blows up and the user doesn't know why.\n\n[Advertisement] **Plan Your .NET 9 Migration with Confidence**\nYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. **Download Free Guide Now!**",
"title": "CodeSOD: Cancel Catch"
}