Why use the correct exception type?
-
I believe that verifying a compressed image would go through exactly the same steps as parsing it would. This is probably the most efficient way. The error message is still stupid though.
Wrong is evil and must be defeated. - Jeff Ello
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
-
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
:doh: I was told by my boss the other day that my biggest weakness is that I always assume people do thing properly.
Wrong is evil and must be defeated. - Jeff Ello
-
:doh: I was told by my boss the other day that my biggest weakness is that I always assume people do thing properly.
Wrong is evil and must be defeated. - Jeff Ello
:laugh:
cheers Chris Maunder
-
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
Because the actual internal error being thrown is an OutOfMemoryException. That has been my experience, especially when working with LEADTools libraries and images with OCR software. Edit: I have seen this similar thing happen before, and for some reason the image "may" be corrupted and thus causes a memory issue. Then the developer just returns a crap message saying not a valid image format. But in reality, the software kept reading the bytes until it ran out of memory.
-
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
Because a useful name for the exception was out-of-the-memory of the developer.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
-
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
The GDI classes seem to be simply a .net facade\interface to the actual underlying code and that code only seems to return generic error messages that are of no help at all. Any issue that happens with GDI simply returns "A generic error occured" even if the error has a specific cause. So I'm going to guess that the reason better exceptions are not thrown is simply because the .net part of the equation doesn't know what the problem is as GDI only bubbles up weird or vague error messages.
-
The GDI classes seem to be simply a .net facade\interface to the actual underlying code and that code only seems to return generic error messages that are of no help at all. Any issue that happens with GDI simply returns "A generic error occured" even if the error has a specific cause. So I'm going to guess that the reason better exceptions are not thrown is simply because the .net part of the equation doesn't know what the problem is as GDI only bubbles up weird or vague error messages.
The return exception is known: out of memory. I have a lot of experience with OCR and images, etc. and this is a common error in underlying C++ libraries when reading the bytes of an image, etc. So, the error is factual and known: out of memory error, usually attributed to an corrupt file format. The user friendly message is still mostly accurate here. It should say something like "your image file format is incorrect or corrupted as the software was unable to process it without error." -- or something like that.
-
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