Hi people,
I'm trying to evaluate the number i.e. error code of an exception thrown within a script. I know that using the class ViException allows me to access "Number" which is not available in the class Exception.
I've tried catching an exception as a ViException. This doesn't work because Visual Studio tells me that I then have an unhandled exception i.e. the exception is not caught properly.
So I try to catch as an exception an Exception. Now I can catch an exception but I am unable to access "Number". It is not possible to cast an Exeption as a ViException.
What I'm trying to do is to evaluate the error code, such that I am able to ignore; for example, duplicate errors (ViException.Number = 810303). This would allow me to skip checking for duplicates before committing the object.
The above stated variants are in the code below. I was wondering if any of you had success in this matter before.
Thanks a lot in advance! - Regards
Ryu
' Variant 1 ' Cannot catch ex as ViException (unhandled exception occurs) Try Using t As New Transaction(Session) object.Save(Session) ' unhandled exception occurs here t.Commit() End Using Catch ex As ViException ' Ignore duplicate errors (810303) If Not CType(ex, ViException).Number.Equals(810303) Then Throw New Exception(ex.InnerException) End If End Try ' Variant 2 ' Cannot cast Exception as ViException Try Using t As New Transaction(Session) object.Save(Session) t.Commit() End Using Catch ex As Exception ' Ignore duplicate errors (810303) If Not CType(ex, ViException).Number.Equals(810303) Then ' Cannot cast type error occurs above Throw New Exception(ex.InnerException) End If End Try