Not all path return a value?
-
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
-
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
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
-
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
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;
-
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
I still get the same error. In fact VS tells me it's unreachable code.
-
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;
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.
-
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
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)
-
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)
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.