Catch Commandline error
Posted
by Bi
on Stack Overflow
See other posts from Stack Overflow
or by Bi
Published on 2010-06-16T00:52:39Z
Indexed on
2010/06/16
1:02 UTC
Read the original article
Hit count: 214
c#
Hi
I am trying to catch an error with an incorrect commandline parameter for the application of form
Myapp.exe myFile.txt
The application however throws an "Unhandled exception - The path is not of legal form".
Below is my code and I am wondering why it does not show the message box as provided in the code? Thanks.
String[] cmdlineArgs = Environment.GetCommandLineArgs();
if (cmdlineArgs.Length == 2)
{
try
{
if (File.Exists(cmdlineArgs[1].ToString()))
ConfigParameters.SetConfigParameters(cmdlineArgs[1].ToString());
else
{
MessageBox.Show("Configuration file does not exist.Restarting...");
Environment.Exit(1);
}
}
catch (Exception ex)
{
}
© Stack Overflow or respective owner