Author Topic: Catching the exception  (Read 1726 times)

rmac

  • Newbie
  • *
  • Posts: 23
    • View Profile
Catching the exception
« on: March 23, 2017, 06:24:21 PM »
Is there a way to catch this exception inside the application?
It's clear I'm getting the error because there is no connection with the PLC, but I would like to be able to catch/report that, instead of getting this pop up message from .Net Framework.
If I hit Continue the program resumes operation, without showing any readings from the PLC of course.
Any help will be appreciated.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Catching the exception
« Reply #1 on: March 23, 2017, 06:37:53 PM »
Is this happening where you are performing a Write with your own code? If so, you need to be sure to wrap all of your Read and Writes in a Try-Catch
Code: [Select]
Try
    EthernetIPforSLCMicroCom1.Write("N7:0","1")
Catch ex as Exception
   msgbox("Write failed. " & ex.message)
End Try
[/doe]

rmac

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Catching the exception
« Reply #2 on: March 23, 2017, 06:50:41 PM »
You are right. As usual.
I'm trying to write/send some values to the PLC from the code.
Will try your suggestion asap.
THANK YOU.

rmac

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Catching the exception
« Reply #3 on: March 23, 2017, 06:53:04 PM »
Should I use Try for every read/write, or I can group several read/write operations inside one Try?

rmac

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Catching the exception
« Reply #4 on: March 23, 2017, 07:05:58 PM »
I put a group of "write to PLC" commands inside the Try and it did work.
I realized that a reaction to the first one is enough.
Got my response to the exception "under control" now.

Thanks again Archie.
Much appreciation.