I am writing an aC # application and want to display error messages on the console or in the message box (depending on the type of application: enum AppTypeChoice {Console, Windows}), and also control how the application continues to work or not (bool StopOnError).
I came up with this method that will check all the criteria, but I get a warning “unreachable code”. I do not understand why!
Here is the whole method (grab some code for fans!)
public void OutputError(string message)
{
string standardMessage = "Something went WRONG!. [ But I'm not telling you what! ]";
string defaultMsgBoxTitle = "Aaaaarrrggggggggggg!!!!!";
string dosBoxOutput = "\n\n*** " + defaultMsgBoxTitle + " *** \n\n Message was: '" + message + "'\n\n";
AppTypeChoice appType = DataDefs.AppType;
DebugLevelChoice level = DataDefs.DebugLevel;
if (level != DebugLevelChoice.None)
{
if (appType == AppTypeChoice.Windows)
MessageBox.Show(message, defaultMsgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
else
Console.WriteLine(dosBoxOutput);
}
else
{
if (appType == AppTypeChoice.Windows)
MessageBox.Show(standardMessage, defaultMsgBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
else
Console.WriteLine(standardMessage);
}
if (DataDefs.StopOnError == true)
Environment.Exit(0);
}
Also, if I have your attention to get the type of application, I just use the constant at the top of the file (e.g. AppTypeChoice.Console in the console application, etc.) - is there a better way to do this (I mean figure out the code if it is a DOS or Windows application)?
, , ... ( , , ?! )