Try catch help with code

Hi there… I’m bravely stepping into lots of new territory. This has to do with try and catch errors.

How would add the catch here so that the program doesn’t crash. It has to do with rate setting from AXWMP (mediaplayer) rate change (speed of playback)

here are the errors that pop up when it crashes.

Error number 1
Error message:Failed on rate
COM.COMException (when hovered over the offending error code

try If mThis = Nil Then Raise New NilObjectException Dim func As New rate_Put_Func1( mThis.Ptr( 0 ).Ptr( 84 ) ) Dim resultCode As Integer = func.Invoke( mThis, value ) If 0 = resultCode Then Else Raise New COM.COMException("Failed on rate", resultCode ) End If end try

Uh… You’re not catching exceptions here, you’re causing them.

If what you want is to stop execution when one of your exceptions occurs, either add one or more catch statements before the End Try statement OR wrap the calling method in a try-catch.

Catch ex as NilObjectException

yeah I got it working using catch. This is so much better than having a program crash :slight_smile: