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. A VS induced horror by me, kinda

A VS induced horror by me, kinda

Scheduled Pinned Locked Moved The Weird and The Wonderful
questionvisual-studiodata-structureshelp
7 Posts 5 Posters 2 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.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    I think my VS is broken or something. I get an error for not writing a return after a catch block. The method in question:

    private bool ReadIni()
    {
    try
    {
    [do stuff]

      if (_\[error string != "" || string array with file content == null\]_)
      {
        _\[return false; among other things\]_
      }
     else
     {
        _\[return true; among other things\]_
     }
    

    }
    catch (Exception ex)
    {
    [display error message]
    }
    return false //WTF?
    }

    T K K M 4 Replies Last reply
    0
    • M Megidolaon

      I think my VS is broken or something. I get an error for not writing a return after a catch block. The method in question:

      private bool ReadIni()
      {
      try
      {
      [do stuff]

        if (_\[error string != "" || string array with file content == null\]_)
        {
          _\[return false; among other things\]_
        }
       else
       {
          _\[return true; among other things\]_
       }
      

      }
      catch (Exception ex)
      {
      [display error message]
      }
      return false //WTF?
      }

      T Offline
      T Offline
      Thomas Weller 0
      wrote on last edited by
      #2

      This is not an error at all... If an exception would occur in the if-condition, the resulting control flow would be without any return statement. So the compiler error is nothing but correct. No broken VS, just malformed code... Regards Thomas

      www.thomas-weller.de Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
      Programmer - an organism that turns coffee into software.

      1 Reply Last reply
      0
      • M Megidolaon

        I think my VS is broken or something. I get an error for not writing a return after a catch block. The method in question:

        private bool ReadIni()
        {
        try
        {
        [do stuff]

          if (_\[error string != "" || string array with file content == null\]_)
          {
            _\[return false; among other things\]_
          }
         else
         {
            _\[return true; among other things\]_
         }
        

        }
        catch (Exception ex)
        {
        [display error message]
        }
        return false //WTF?
        }

        K Offline
        K Offline
        killabyte
        wrote on last edited by
        #3

        Why wouldnt you return something from the function declared private **bool** ReadIni();

        J 1 Reply Last reply
        0
        • K killabyte

          Why wouldnt you return something from the function declared private **bool** ReadIni();

          J Offline
          J Offline
          Jeroen De Dauw
          wrote on last edited by
          #4

          My guess is that you then can do something like:

          if (ReadIni())
          {
          // do something with the data
          }
          else
          {
          // show error
          }

          GSoC 2009 student for SMW! --- My little forums: http://code.bn2vs.com --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

          K 1 Reply Last reply
          0
          • M Megidolaon

            I think my VS is broken or something. I get an error for not writing a return after a catch block. The method in question:

            private bool ReadIni()
            {
            try
            {
            [do stuff]

              if (_\[error string != "" || string array with file content == null\]_)
              {
                _\[return false; among other things\]_
              }
             else
             {
                _\[return true; among other things\]_
             }
            

            }
            catch (Exception ex)
            {
            [display error message]
            }
            return false //WTF?
            }

            K Offline
            K Offline
            Kenneth Ballard
            wrote on last edited by
            #5

            Code similar to this would produce a warning in VC++ that not all execution paths have a return statement. In the catch block, there's the possibility the code could continue past the catch block, thus reaching the end of the function, so it'd look as if the function didn't have a return statement at the end for a function with a return time other than void.

            1 Reply Last reply
            0
            • J Jeroen De Dauw

              My guess is that you then can do something like:

              if (ReadIni())
              {
              // do something with the data
              }
              else
              {
              // show error
              }

              GSoC 2009 student for SMW! --- My little forums: http://code.bn2vs.com --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

              K Offline
              K Offline
              killabyte
              wrote on last edited by
              #6

              to validate the if statement the funtion WOULD return a bool type...... which was my point WTF is going on here

              1 Reply Last reply
              0
              • M Megidolaon

                I think my VS is broken or something. I get an error for not writing a return after a catch block. The method in question:

                private bool ReadIni()
                {
                try
                {
                [do stuff]

                  if (_\[error string != "" || string array with file content == null\]_)
                  {
                    _\[return false; among other things\]_
                  }
                 else
                 {
                    _\[return true; among other things\]_
                 }
                

                }
                catch (Exception ex)
                {
                [display error message]
                }
                return false //WTF?
                }

                M Offline
                M Offline
                Megidolaon
                wrote on last edited by
                #7

                As I said, a horropr made by me. I just realized that it has to be this way. I guess that's what ages opf windows forms programming with only void methods can do to you, you forget the basics of functions. :doh:

                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