Is there a way to jump to a different spot in my coding if I get to this?:
Catch exp As Exception
Thanks!
Brenda
Printable View
Is there a way to jump to a different spot in my coding if I get to this?:
Catch exp As Exception
Thanks!
Brenda
well what do you mean by JUMP??? it sounds like a dreaded GOTO if you are talking about what I think you are talking about... but lets say you had a sub routine to handle something, you could certainly call it from the catch block
but please clarify what you mean exactly.VB Code:
Try 'Code here Catch exp As Exception MySubroutine 'calls subroutine to do stuff End Try
OK. This is what I have:
VB Code:
ElseIf dr("PartNumber") = 5 Then Dim Insert_case As String Insert_case = "INSERT INTO tblCapRec (CaseNumber,PartNumber,Status,InGDB, " & _ "DocsOrdered,DocsHere,AppHere,Ubum,Suspended,Trace,SentToHUD,SentToTSI, " & _ "SentToCredit,SpanishCase,PropAddress,PropCity,PropState,PropZipCode,Updated, " & _ "MailKey,MailedFirst,MortgageAmt,PaidUpFront,EndorseDate,Term,MatureDate,EncumDate, " & _ "HoldingMor,ServingMor,RcvdFromOld,RcvdFromRegular,RcvdFromRtn,RcvdFrom2s,RefundAmt, " & _ "RateCharged,FeeAmount,RemainingDue,AfterFee,AmtPaid,LateFees,LastName,FirstName, " & _ "MailAddress,MailCity,MailState,MailZipCode,HomePhone) " & _ "SELECT CaseNumber,6,2,0,0,0,0,0,0,0,0,0,0,0,PropAddress,PropCity,PropState, " & _ "PropZipCode,GETDATE(),1,GETDATE(),MortgageAmt,PaidUpFront,EndorseDate,Term, " & _ "MatureDate,EncumDate,HoldingMor,ServingMor,0,0,0,0,RefundAmt,RateCharged, " & _ "FeeAmount,RemainingDue,AfterFee,0,0,'" & txtLastName.Text & "','" & txtFirstName.Text & "', " & _ "'" & txtAddress.Text & "','" & txtCity.Text & "','" & cbStates.Text & "', " & _ "'" & txtZipCode.Text & "','" & txtPhone.Text & "' " & _ "FROM tblCapRec WHERE CaseNumber = '" & g_CaseNum & "' AND PartNumber = " & g_PartNum & "" Dim SqlConn1 As SqlConnection = New SqlConnection(strConnectionString) Dim cmdSqlCommand1 As SqlCommand = New SqlCommand(Insert_case, SqlConn1) Try g_PartNum = 6 cmdSqlCommand1.Connection.Open() cmdSqlCommand1.ExecuteScalar() [color=red]Catch exp As Exception[/color] MessageBox.Show(exp.Message) Exit Sub Finally If SqlConn1.State = ConnectionState.Open Then SqlConn1.Close() End If End Try
If it gets to the Catch Exception, I would like to jump to the next ElseIf Statement. Or is that bad to do?
Brenda
you cant do that without a goto, is goto even supported anymore in .net?? If it is its for backwards compatibility (very backwards). even if it was, it would be HIGHLY HIGHLY NOT RECOMMENDED to use it... that being said, what is the next elseif anyway? if it is just some cleanup code or something like that, put it in its own subroutine, so you can call it from wherever you need to call it from and you wont have nasty spaghetti code.
Yes it is. :sick:Quote:
Originally posted by kleinma
you cant do that without a goto, is goto even supported anymore in .net??
brendalisalowe, what happens in the next ElseIf statement? Would that ElseIf block be called ONLY if there's an exception?
Also, shouldn't you be checking for SQLException?
So this is better to do?:
Catch exp As SqlException
I need to think more about what I am trying to do in my coding with the ElseIF. I'll let you know what I think later today. Thanks!
Brenda
Your next elseif should be checking for another part #, not checking for some database error.
Besides the subroutine method described above, you can throw the exception and have it caught elsewhere. But the next elseif isn't a good place to do that.