How to edit existing expression?

Hello

Below is a journal that creates an expression and if run the second time it should edit expression value that was created in the first run. Do i need another block of code to handle errors?

Imports System
Imports NXOpen

Module create expression

Public theSession As Session = Session.GetSession()
Public workPart As Part = theSession.Parts.Work

Sub Main()

Dim leftPart As String = "12"
Dim expression1 As NXOpen.Expression = Nothing
Dim thr_exp As NXOpen.Expression = Nothing
Dim expression_a As String = "thr_txt"

'create expression

Try
Dim theExp As Expression = workPart.Expressions.FindObject(expression_a)

workPart.Expressions.Edit(theExp, "M""+stringValue( " & leftPart & " )")

Catch ex As NXException
ex.AssertErrorCode(3520016)

expression1 = workPart.Expressions.CreateExpression("String", expression_a & "=""M""+stringValue( " & leftPart & " )")
End Try

End Sub

Private Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub

Public Function GetUnloadOption(ByVal arg As String) As Integer
Return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately)
End Function

End Module

I don't recommend asserting error codes in this case. In the Try Catch block, you can test for a certain, known error code by using an If block (i.e. the 'object not found' code in your case).

In the 'expressions' article, I use a Try Catch block to create an expression; if the expression already exists, I get a known error in the Catch block and retrieve the existing expression instead. If a different (unexpected) error is thrown, the message is shown to the user.

http://nxjournaling.com/content/expressions-creating-expressions-no-units