I have a method in a C# program that essentially looks like this:
public bool Connect()
{
try
{
// try to connect
return true;
}
catch(MySqlException e)
{
throw new CustomException(e.Message);
return false;
}
}
The issue is about the order of these specific lines. The compiler complains about this and indicates the return
statement as unreachable code:
throw new CustomException(e.Message);
return false;
But it does not complain about this:
return false;
throw new CustomException(e.Message);
Why does the first one not work, but the second one does? Doesn't a method exit as soon as it hits a return
statement?