-
May 25th, 2021, 07:25 AM
#1
Problem with try catch to show error message.
I don't get any error message if type a faulty computer name
Can someone help me, how I can get it done?
HTML Code:
try
{
buttonStatus.Enabled = false;
statusComputer = textBoxComputer.Text;
ProcessStartInfo status = new ProcessStartInfo("cmd");
status.Arguments = "/c systeminfo /s " + statusComputer + " | findstr /B " + winVersion + " " + osName + " " + systemInfo + " " + installDate;
//mesessageBox.Show(checkComputer);
status.UseShellExecute = false;
status.CreateNoWindow = true;
status.WindowStyle = ProcessWindowStyle.Hidden;
status.RedirectStandardOutput = true;
status.RedirectStandardInput = false;
var prog = Process.Start(status);
string statustext = prog.StandardOutput.ReadToEnd();
richTextBoxStatus.Text = statustext;
MessageBox.Show("Task completed!");
}
catch
{
MessageBox.Show("Error!");
}
buttonStatus.Enabled = true;
-
May 25th, 2021, 04:53 PM
#2
Re: Problem with try catch to show error message.
You need to catch an Exception.
Code:
catch(Exception ex)
{
MessageBox.Show($"Error! Message: {ex.Message}.");
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|