Why use the correct exception type?
-
Pretty much my assumption. "Let's try it and see what breaks".
cheers Chris Maunder
Chris Maunder wrote:
"Let's try it and see what breaks".
Now you got my attention. Theory shmeory. Fire it up and try it out. :thumbsup: :laugh: Just like division by zero. People say it can't be done. Well... I at least want to try it a few times. :laugh:
-
Chris Maunder wrote:
"Let's try it and see what breaks".
Now you got my attention. Theory shmeory. Fire it up and try it out. :thumbsup: :laugh: Just like division by zero. People say it can't be done. Well... I at least want to try it a few times. :laugh:
raddevus wrote:
I at least want to try it a few times.
Isn't that the definition of stupid - repeat the same action with the same settings and expect different results!
Never underestimate the power of human stupidity RAH
-
raddevus wrote:
I at least want to try it a few times.
Isn't that the definition of stupid - repeat the same action with the same settings and expect different results!
Never underestimate the power of human stupidity RAH
-
From the docs for
Image.FromFile
Quote:
Exceptions OutOfMemoryException The file does not have a valid image format. -or- GDI+ does not support the pixel format of the file.
...and using something like
UnsupportedFormatException
is too hard? :doh:cheers Chris Maunder
In a moment of clarity, I recalled the answer: they are applying the Maunder Minimum. 8)
-
From the docs for
Image.FromFile
Quote:
Exceptions OutOfMemoryException The file does not have a valid image format. -or- GDI+ does not support the pixel format of the file.
...and using something like
UnsupportedFormatException
is too hard? :doh:cheers Chris Maunder
Chris Maunder wrote:
and using something like
UnsupportedFormatException
is too hard?Just be glad its not the usual, "Error occurred", Good luck figuring it out. :sigh:
Common sense is admitting there is cause and effect and that you can exert some control over what you understand.
-
From the docs for
Image.FromFile
Quote:
Exceptions OutOfMemoryException The file does not have a valid image format. -or- GDI+ does not support the pixel format of the file.
...and using something like
UnsupportedFormatException
is too hard? :doh:cheers Chris Maunder
Looks like it's the same reason why renaming an EXE to COM and trying to load it generates an "Out of memory" error: Implementation details leaking to the surface.
-
In the case that affected me it was an attempt to load an SVG file which I discovered isn't supported. A simple check of filename or the first few bytes of the file would have found this. There's even a handy list[^] they could refer to.
cheers Chris Maunder
Extensions aren't trustworthy, nothing guarantees the file is in the format it says it's on. The developer himself might have changed the extension to better suit his application, as evidenced by the shitload of formats that are just XML files, compressed or not, with a different extension (like SVG). As for the first few bytes, many formats have common prefixes (there's 2 or 3 exemples on the list you linked, but there's more), some of them don't even require the prefix to be present and others (like SVG) are encoded as text that can have yet another prefix (BOM). It's sad, but we can't trust the format markers when dealing with multiple formats.
-
Looks like it's the same reason why renaming an EXE to COM and trying to load it generates an "Out of memory" error: Implementation details leaking to the surface.
I mean, not really? COM files have a size limit because they behave different from EXE files (or rather, EXE files behave different, since COM is the original). When you try to load a COM file that exceeds this limit you're really running out of memory, before the code can even start to be executed. Could they read the file size and predict that? they couldn't (or just didn't, hard to say with stuff this old) when COM files where actually being used, so the current included loaders also don't. You don't really want to mess with those kinds of legacy systems, specially when they are useless for current developments and the alternative doesn't share the concerns. [COM file - Wikipedia](https://en.wikipedia.org/wiki/COM\_file#MS-DOS\_binary\_format)
-
raddevus wrote:
I at least want to try it a few times.
Isn't that the definition of stupid - repeat the same action with the same settings and expect different results!
Never underestimate the power of human stupidity RAH
I grew up learning: "If at first you don't succeed, try, try again." That philosophy has done well for me. Now, when I suggest it to my teenage son, I get "The definition of insanity is trying the same thing over and over and expecting a different result." It's really a way to get out of trying to do a good job.
-
I grew up learning: "If at first you don't succeed, try, try again." That philosophy has done well for me. Now, when I suggest it to my teenage son, I get "The definition of insanity is trying the same thing over and over and expecting a different result." It's really a way to get out of trying to do a good job.
I prefer the "Theory of one" If it works for one case, it must work for them all. :-D
-
From the docs for
Image.FromFile
Quote:
Exceptions OutOfMemoryException The file does not have a valid image format. -or- GDI+ does not support the pixel format of the file.
...and using something like
UnsupportedFormatException
is too hard? :doh:cheers Chris Maunder
Don't care, I always use
catch(Exception e){..}
That always works ;P
-
raddevus wrote:
I at least want to try it a few times.
Isn't that the definition of stupid - repeat the same action with the same settings and expect different results!
Never underestimate the power of human stupidity RAH
Mycroft Holmes wrote:
sn't that the definition of stupid - repeat the same action with the same settings and expect different results!
It is stupid, until it works. Which will be just when I{m showing nmy wife that it won{t work.
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
-
Could have been worse... A
MysteriousException
, or aConfusingException
instead."I'm neither for nor against, on the contrary." John Middle