CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2018
    Posts
    12

    Lightbulb 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;

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured