Author Topic: Try-Catch in Visual Basic Script VB  (Read 16881 times)

Hoefler1

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Try-Catch in Visual Basic Script VB
« on: August 11, 2016, 01:57:15 am »
Can anyone tell me why this would not work? There is an error " 'Function' expected" appearing in the line with "End Try".
There are basically 3 cases:
1. The GUID of the AttrClassifier is in OwnElems -> set IsValid = true
2. The GUID is not in OwnElems -> set IsValid = false
3. There is no Element with the ID of the Classifier (Catch the Exception thrown in first line of Try-Block) -> set IsValid = true

Code: [Select]
public function Validate(item)
dim validationResult
set validationResult = new ValidationResult
...
Try
Dim AttrClassifier As EA.Element = Repository.GetElementByID(Attribute.ClassifierID)
Dim guid
Set guid = AttrClassifier.ElementGUID
If THandler.OwnElems.Contains(guid) Then
validationResult.IsValid = true
set Validate = validationResult
Else
validationResult.IsValid = false
set Validate = validationResult
End If
Catch Exception
validationResult.IsValid = true
set Validate = validationResult
Return 'ignore default classifiers and elements without classifier
End Try
end function

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Try-Catch in Visual Basic Script VB
« Reply #1 on: August 11, 2016, 02:06:33 am »
There is no try-catch in VBScript. See http://stackoverflow.com/questions/4999364/try-catch-end-try-in-vbscript
VBScript <> VB

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
Re: Try-Catch in Visual Basic Script VB
« Reply #2 on: August 11, 2016, 08:52:44 am »
For an explanation of what it does have and how to handle errors:
http://stackoverflow.com/questions/157747/vbscript-using-error-handling#157785