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