Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Try Catch but to generate an error
Message
De
17/02/2009 04:06:59
 
 
À
16/02/2009 18:41:33
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01382228
Message ID:
01382289
Vues:
29
>I have an interesting situation here and I would like to know if this is possible. On one specific condition, when I do a DataFill(), I need to do it within a Try Catch syntax. So, if there is an error, I can act accordingly. But, this is only effective if this is a specific error. For all the rest, I would like the code to generate the error as is. So, basically, I have something like this:
>
>
>                        Try
>
>                            ' Start time
>                            lnDateNow = Date.Now.Ticks
>
>                            oDataAdapter.Fill(oDataSet)
>
>                            ' End time
>                            lnDateNow2 = Date.Now.Ticks
>
>                            ' This means the command worked ok so we are ok to exit
>                            Exit For
>
>                        Catch loError As Exception
>
>                            ' If this is the deadlock issue
>                            If oApp.At("was deadlocked on lock ", loError.Message) > 0 Then
>
>                                ' If we have not reached the maximum tries of 10, we retry
>                                If lnCounter < 5 Then
>
>                                    If lnCounter > 1 Then
>
>                                        ' Log an error
>                                        loInsertRow.cAlias = "Error"
>                                        loInsertRow.ParameterAdd("Message", "SQL Server deadlock issue " + lnCounter.ToString + " " + _
>                                         loError.Message + oApp.cCR + oApp.cCR + ErrorDetail())
>                                        loInsertRow.ParameterAdd("Page", oProcess.cPageFullName)
>                                        loInsertRow.ParameterAdd("QueryStrin", oProcess.cQueryString)
>                                        loInsertRow.ParameterAdd("StackTrace", "")
>                                        loInsertRow.ParameterAdd("IP", oProcess.cIP)
>                                        loInsertRow.ParameterAdd("NoLanguage", oProcess.nLanguage)
>                                        loInsertRow.ParameterAdd("Property", "")
>                                        If Not loInsertRow.InsertRow() Then
>                                            Return False
>                                        End If
>
>                                    End If
>
>                                    ' Wait for 1 second
>                                    System.Threading.Thread.Sleep(1000)
>
>                                Else
>                                    Return False
>                                End If
>
>                            Else
>
>                                ' This is a regular error, so we have to let the system deals with it
>
>                            End If
>
>                        End Try
>
>
>So, basically, in the Catch section, if the error is not about the deadlock issue, I would like the application to act as if I wouldn't have had any Try Catch at all. So, after the ' This is a regular error line, is there something I can put in there to provoke this error as is?

Just 'Throw loError'
Or you could wrap it in a new exception:
Throw new Exception("My code failed",loError)
You could also consider using a more restricted type of exception in the catch - probably DataException
Regards,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform