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. General Programming
  3. C#
  4. Not all path return a value?

Not all path return a value?

Scheduled Pinned Locked Moved C#
data-structureshelpquestion
7 Posts 4 Posters 0 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 get this error, even though I don't know why. The code throwing this error is this:

    bool ReadIni()
    {
    try
    {
    string error = "";
    try
    {
    //read ini from file
    }
    catch (Exception ex)
    {
    //show error message, but continue because the user is promtped to input the
    //values manually and file will be created.
    }

                if (ini != null) //ini is a string array filled with the content of the ini file
                {
                    //parse values from ini and store sucess in an array
                    //write error message to string error
                }
                else
                {
                    for (int i = 0; i < 5; i++)
                    {
                        conversion\[i\] = false; //set all bools in the array to false
                    }
                }
                //this part seems throw the error
                if (error != "" || ini == null)
                {
                    //show error message
                    MessageBox.Show(error + "\\r\\nPlease input the missing values", "Input missing 
                    values", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
                    //initialize F\_Manual\_Input with array       //bool       int     string 
                    F\_Manual\_Input forminput = new F\_Manual\_Input(conversion, values, inipath);
                    this.Show(); //show this form as first as "background" starting up
                    forminput.ShowDialog();
                    //set map and tile size with manually input values 
                    this.mapsize = new Size(forminput.MapWidth, forminput.MapHeight);
                    this.tilewidth = forminput.TileWidth;
                    this.tileheight = forminput.TileHeight;
    
                    return false; //values had to be manually input
                }
                else
                {
                    //set map/tile size and image width with values from file
                    this.mapsize = new Size(sizeX, sizeY);
                    this.tilewidth = tileX;
                    this.tileheight = tileY;
                    this.imagewidth = sourceX;
    
                    return true; //input was read from file
                }
            }
            catch (Exception ex)
            {
                Me
    
    M 1 S 3 Replies Last reply
    0
    • M Megidolaon

      I get this error, even though I don't know why. The code throwing this error is this:

      bool ReadIni()
      {
      try
      {
      string error = "";
      try
      {
      //read ini from file
      }
      catch (Exception ex)
      {
      //show error message, but continue because the user is promtped to input the
      //values manually and file will be created.
      }

                  if (ini != null) //ini is a string array filled with the content of the ini file
                  {
                      //parse values from ini and store sucess in an array
                      //write error message to string error
                  }
                  else
                  {
                      for (int i = 0; i < 5; i++)
                      {
                          conversion\[i\] = false; //set all bools in the array to false
                      }
                  }
                  //this part seems throw the error
                  if (error != "" || ini == null)
                  {
                      //show error message
                      MessageBox.Show(error + "\\r\\nPlease input the missing values", "Input missing 
                      values", MessageBoxButtons.OK, MessageBoxIcon.Error);
      
                      //initialize F\_Manual\_Input with array       //bool       int     string 
                      F\_Manual\_Input forminput = new F\_Manual\_Input(conversion, values, inipath);
                      this.Show(); //show this form as first as "background" starting up
                      forminput.ShowDialog();
                      //set map and tile size with manually input values 
                      this.mapsize = new Size(forminput.MapWidth, forminput.MapHeight);
                      this.tilewidth = forminput.TileWidth;
                      this.tileheight = forminput.TileHeight;
      
                      return false; //values had to be manually input
                  }
                  else
                  {
                      //set map/tile size and image width with values from file
                      this.mapsize = new Size(sizeX, sizeY);
                      this.tilewidth = tileX;
                      this.tileheight = tileY;
                      this.imagewidth = sourceX;
      
                      return true; //input was read from file
                  }
              }
              catch (Exception ex)
              {
                  Me
      
      1 Offline
      1 Offline
      12Code
      wrote on last edited by
      #2

      Megidolaon wrote:

      else { //set map/tile size and image width with values from file this.mapsize = new Size(sizeX, sizeY); this.tilewidth = tileX; this.tileheight = tileY; this.imagewidth = sourceX; return true; //input was read from file }

      add another

      return false;

      after the code.

      ;)*12Code

      M 1 Reply Last reply
      0
      • M Megidolaon

        I get this error, even though I don't know why. The code throwing this error is this:

        bool ReadIni()
        {
        try
        {
        string error = "";
        try
        {
        //read ini from file
        }
        catch (Exception ex)
        {
        //show error message, but continue because the user is promtped to input the
        //values manually and file will be created.
        }

                    if (ini != null) //ini is a string array filled with the content of the ini file
                    {
                        //parse values from ini and store sucess in an array
                        //write error message to string error
                    }
                    else
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            conversion\[i\] = false; //set all bools in the array to false
                        }
                    }
                    //this part seems throw the error
                    if (error != "" || ini == null)
                    {
                        //show error message
                        MessageBox.Show(error + "\\r\\nPlease input the missing values", "Input missing 
                        values", MessageBoxButtons.OK, MessageBoxIcon.Error);
        
                        //initialize F\_Manual\_Input with array       //bool       int     string 
                        F\_Manual\_Input forminput = new F\_Manual\_Input(conversion, values, inipath);
                        this.Show(); //show this form as first as "background" starting up
                        forminput.ShowDialog();
                        //set map and tile size with manually input values 
                        this.mapsize = new Size(forminput.MapWidth, forminput.MapHeight);
                        this.tilewidth = forminput.TileWidth;
                        this.tileheight = forminput.TileHeight;
        
                        return false; //values had to be manually input
                    }
                    else
                    {
                        //set map/tile size and image width with values from file
                        this.mapsize = new Size(sizeX, sizeY);
                        this.tilewidth = tileX;
                        this.tileheight = tileY;
                        this.imagewidth = sourceX;
        
                        return true; //input was read from file
                    }
                }
                catch (Exception ex)
                {
                    Me
        
        M Offline
        M Offline
        Murugesan G
        wrote on last edited by
        #3

        Just put return statment after the catch blok, catch (Exception ex) { MessageBox.Show("An error occurred while reading the ini file:\r\n" + ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return false;

        M 1 Reply Last reply
        0
        • 1 12Code

          Megidolaon wrote:

          else { //set map/tile size and image width with values from file this.mapsize = new Size(sizeX, sizeY); this.tilewidth = tileX; this.tileheight = tileY; this.imagewidth = sourceX; return true; //input was read from file }

          add another

          return false;

          after the code.

          ;)*12Code

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

          I still get the same error. In fact VS tells me it's unreachable code.

          1 Reply Last reply
          0
          • M Murugesan G

            Just put return statment after the catch blok, catch (Exception ex) { MessageBox.Show("An error occurred while reading the ini file:\r\n" + ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return false;

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

            The method is supposed to continue if there's an error with read the ini file in the first place (like missing file, etc.). The user must enter the values manually and the application will create the ini from scratch.

            1 Reply Last reply
            0
            • M Megidolaon

              I get this error, even though I don't know why. The code throwing this error is this:

              bool ReadIni()
              {
              try
              {
              string error = "";
              try
              {
              //read ini from file
              }
              catch (Exception ex)
              {
              //show error message, but continue because the user is promtped to input the
              //values manually and file will be created.
              }

                          if (ini != null) //ini is a string array filled with the content of the ini file
                          {
                              //parse values from ini and store sucess in an array
                              //write error message to string error
                          }
                          else
                          {
                              for (int i = 0; i < 5; i++)
                              {
                                  conversion\[i\] = false; //set all bools in the array to false
                              }
                          }
                          //this part seems throw the error
                          if (error != "" || ini == null)
                          {
                              //show error message
                              MessageBox.Show(error + "\\r\\nPlease input the missing values", "Input missing 
                              values", MessageBoxButtons.OK, MessageBoxIcon.Error);
              
                              //initialize F\_Manual\_Input with array       //bool       int     string 
                              F\_Manual\_Input forminput = new F\_Manual\_Input(conversion, values, inipath);
                              this.Show(); //show this form as first as "background" starting up
                              forminput.ShowDialog();
                              //set map and tile size with manually input values 
                              this.mapsize = new Size(forminput.MapWidth, forminput.MapHeight);
                              this.tilewidth = forminput.TileWidth;
                              this.tileheight = forminput.TileHeight;
              
                              return false; //values had to be manually input
                          }
                          else
                          {
                              //set map/tile size and image width with values from file
                              this.mapsize = new Size(sizeX, sizeY);
                              this.tilewidth = tileX;
                              this.tileheight = tileY;
                              this.imagewidth = sourceX;
              
                              return true; //input was read from file
                          }
                      }
                      catch (Exception ex)
                      {
                          Me
              
              S Offline
              S Offline
              Spunky Coder
              wrote on last edited by
              #6

              Declare a local bool variable first and then set the variable to either true or false in the IF ELSE blocks. In the end return the variable The code should look like the following...

              bool ReadIni()
              {
              bool returnValue = false;
              try
              {
              // Your code implementation

                      }
                       catch (Exception ex)
                      {
                        //Your code
                      }
              

              return returnValue
              }

              "Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)

              M 1 Reply Last reply
              0
              • S Spunky Coder

                Declare a local bool variable first and then set the variable to either true or false in the IF ELSE blocks. In the end return the variable The code should look like the following...

                bool ReadIni()
                {
                bool returnValue = false;
                try
                {
                // Your code implementation

                        }
                         catch (Exception ex)
                        {
                          //Your code
                        }
                

                return returnValue
                }

                "Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)

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

                Yeah, it never happened to me, but I realized that in case of an exception, that exception is caught and afterwards the application continues normally. Thus in this case it also need a return value.

                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