I have defined 2 custom exceptions like
Public Class SkipException
Inherits System.ApplicationException
End Class
Public Class NoRecordFoundException
Inherits System.ApplicationException
End Class
In my code the scenarios are 1. Data causes general exception 2. I dont have the data 3. Exception I have handled already
Try
'Some code here
Try
''Do some code
''Cant find the record
If i = 0 then
Throw NoRecordFoundException
End if
Catch ex as Exception
End Try
Try
''Cant do nothing so just skip
If CantDoNothing then
Throw SkipException
End if
Catch ex as Exception
End Try
Catch SkipException
''Some code here
Catch NoRecordFoundException
'' some code here
Catch ex as Exception
''Handle regular exception
End Try
So will this work? Will the exception go to the outer handling and not the inner catch?
Right now, Im re-Throwing the exception to get it working.
Throw New NoRecordFoundException(). The internalCatchwill catch it (if it was doing something with it). You could have something likeThrow new Exception("Inner", New SkipException())and inCatch ex As Exception,if ex.InnerException is SkipException then Throw ex.InnerException. This will be caught by the externalCatch SkipException. But, the internalTryblock could just have aFinallyblock instead of aCatchblock, so the externalCatchblocks would catch all the exceptions.Ifblocks or a few variable to track the current state might be more appropriate.