Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Why use the correct exception type?

Why use the correct exception type?

Scheduled Pinned Locked Moved The Weird and The Wonderful
winformsgraphicsquestion
29 Posts 20 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C 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

    S Offline
    S Offline
    S Douglas
    wrote on last edited by
    #21

    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.

    1 Reply Last reply
    0
    • C 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

      K Offline
      K Offline
      Kirill Illenseer
      wrote on last edited by
      #22

      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.

      S 1 Reply Last reply
      0
      • C 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

        S Offline
        S Offline
        Sentenryu
        wrote on last edited by
        #23

        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.

        1 Reply Last reply
        0
        • K Kirill Illenseer

          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.

          S Offline
          S Offline
          Sentenryu
          wrote on last edited by
          #24

          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)

          1 Reply Last reply
          0
          • M Mycroft Holmes

            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

            B Offline
            B Offline
            Bruce Patin
            wrote on last edited by
            #25

            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.

            L 1 Reply Last reply
            0
            • B Bruce Patin

              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.

              L Offline
              L Offline
              littleGreenDude
              wrote on last edited by
              #26

              I prefer the "Theory of one" If it works for one case, it must work for them all. :-D

              1 Reply Last reply
              0
              • C 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

                C Offline
                C Offline
                Christiaan van Bergen
                wrote on last edited by
                #27

                Don't care, I always use

                catch(Exception e){..}

                That always works ;P

                1 Reply Last reply
                0
                • M Mycroft Holmes

                  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

                  D Offline
                  D Offline
                  Dr Walt Fair PE
                  wrote on last edited by
                  #28

                  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

                  1 Reply Last reply
                  0
                  • P phil o

                    Could have been worse... A MysteriousException, or a ConfusingException instead.

                    "I'm neither for nor against, on the contrary." John Middle

                    S Offline
                    S Offline
                    Smart K8
                    wrote on last edited by
                    #29

                    ...or even worse: GeneralException - exception that can be anything from anywhere.. sorry, no stack.

                    In order to understand stack overflow, you must first understand stack overflow.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups