1 Reply Latest reply on Jan 17, 2018 9:09 AM by Patrick.Cashman

    How to  prevent App crashing in .net

    etib@rafael.co.il

      Hello

       

      I am developing automation using c# .Net

       

      I'm looking for way to prevent app crashing like Scripting.DontExit = true

      this way used in VB Script, does anyone know how to do this in .net , does it possible?

       

      thanks
      Ester

        • 1. Re: How to  prevent App crashing in .net
          Patrick.Cashman

          Figure out where it's crashing and then use a Try Catch block.  If an exception fault happens, the Try Catch will skip over it and keep going.

           

          You can also put a pcbdoc.transactionstart and transactionend in there, and put a second transactionend statement in the Catch area so that even if a failure happens in your transaction, it gets closed in the Catch and doesn't hang up Expedition like it would if an open transaction encounters a fatal error. Here's an example with both Try/Catch and Transaction:

           

          'redraw the board outline

                  Try

                      If doc.TransactionStart(0) = True Then

                          For Each shp In bo_mask.Shapes

                              ptary = shp.PointsArray

                              pts = UBound(ptary, 2) + 1

                              new_bo = doc.PutBoardOutline(pts, ptary, 0)

                          Next

                          doc.TransactionEnd(True)

                      End If

                  Catch ex As Exception

                      doc.TransactionEnd(False)

                      Debug.Print("creation of new board outline failed with an error message of " & ex.Message)

                  End Try

          The ex variable initialized in the Catch statement has some additional functionality, such as ex.Message as used in the debug statement.

          Of course if there is a failure you may want to alert the user in some way, exit the subroutine or function, or whatever else is needed to terminate the action cleanly without killing the application.