Results 1 to 4 of 4

Thread: Catching “unhandled exception” caused by a Process

  1. #1
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,559

    Question Catching “unhandled exception” caused by a Process

    My code looks something like this:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        Dim myProcess As New Process
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.StartInfo.WorkingDirectory = "X:\folder\where\console\program\resides"
        myProcess.StartInfo.FileName = "third_party_console_program.exe"
        myProcess.StartInfo.Arguments = "some: arguments goes here"
        myProcess.Start()
        myProcess.WaitForExit()
    
        MsgBox("Done")
    End Sub
    I am using Process to start a console program. What this console program does is, it would detect whether a particular device is connected via usb, and tries to read some block of data. But the problem is, when no devices are connected, it is giving an unhandled exception(this is thrown by the console_program. Not my WinForm program). When a device is connected, no problem is there !

    I think it is probably trying to read from the usb, even when it doesn't detect any device. Since this console app is of a third party program, I couldn't do anything on it.

    Instead what I am trying to do is, to catch the unhandled exception and output the message "Couldn't detect the device !"

    But the normal Try..Catch block covered on the above piece of code won't work as I think the exception is thrown on a separate thread.

    Any ideas on how to catch this ? Any tips or suggestions would be very helpful.

    Thank you

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    81,257

    Re: Catching “unhandled exception” caused by a Process

    You may find that the ExitCode property of the Process will indicate whether the program exited normally or errored out. If not then you may have to redirect the StandardError stream of the Process.

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,559

    Re: Catching “unhandled exception” caused by a Process

    Quote Originally Posted by jmcilhinney View Post
    You may find that the ExitCode property of the Process will indicate whether the program exited normally or errored out. If not then you may have to redirect the StandardError stream of the Process.
    Thanks

    I tried checking the ExitCode. But it is always returning a 0 (which is supposed to be returned only for for successful execution). Also tried redirecting error and output stream. But both are returning empty.

    I have tried running the console program from Command Prompt(passing parameters). But there also, it gives the unhandled exception after echoing two lines:
    Code:
      XXXXXXXXXXX
      Looking for usb interface devices
      No device found
    After these two lines echoed to cmd, after a 3 secs, it shows the unhandled exception ! When I close the error message, it goes back to the prompt.

    That's how I assumed that the console program is trying to continue reading even after no devices are found ! So, any ways to catch this unhandled exception thrown by the console program ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  4. #4
    Lively Member
    Join Date
    Jan 12
    Posts
    80

    Re: Catching “unhandled exception” caused by a Process

    I have tried this and also get same error as akhileshbc

    VbAzza

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •