Function does not return value on all code paths [modified]
-
Hi, I am using a simple function which returns a dataset. I get a warning that function does not return value on all code paths.Normally i just say throw in the catch block, which solves the problem. But as i am implementing enterprise exception block the suggestion is to use a policy with if(rethrow) statement, which i beleive creates the warning as throw is hidden inside if statement. I can say return nothing at the end of catch but i was wondering What is the best way to get rid of the warning. Public Function SearchEscalationMails() As DataSet Try Dim dbResourcePlanning As Database = DatabaseFactory.CreateDatabase() Dim strProcName As String = "SearchMailEscalations" Dim dbSPCommand As DbCommand = dbResourcePlanning.GetStoredProcCommand (strProcName) dbResourcePlanning.ExecuteDataSet(dbSPCommand) Return dbResourcePlanning.ExecuteDataSet(dbSPCommand) Catch ex As Exception Dim bRethrow As Boolean bRethrow = ExceptionPolicy.HandleException(ex, "BusinessLayerPolicy") If (bRethrow) Then Throw End If End Try End Function -- modified at 10:49 Sunday 29th April, 2007
-
Hi, I am using a simple function which returns a dataset. I get a warning that function does not return value on all code paths.Normally i just say throw in the catch block, which solves the problem. But as i am implementing enterprise exception block the suggestion is to use a policy with if(rethrow) statement, which i beleive creates the warning as throw is hidden inside if statement. I can say return nothing at the end of catch but i was wondering What is the best way to get rid of the warning. Public Function SearchEscalationMails() As DataSet Try Dim dbResourcePlanning As Database = DatabaseFactory.CreateDatabase() Dim strProcName As String = "SearchMailEscalations" Dim dbSPCommand As DbCommand = dbResourcePlanning.GetStoredProcCommand (strProcName) dbResourcePlanning.ExecuteDataSet(dbSPCommand) Return dbResourcePlanning.ExecuteDataSet(dbSPCommand) Catch ex As Exception Dim bRethrow As Boolean bRethrow = ExceptionPolicy.HandleException(ex, "BusinessLayerPolicy") If (bRethrow) Then Throw End If End Try End Function -- modified at 10:49 Sunday 29th April, 2007
-
Hi, I am using a simple function which returns a dataset. I get a warning that function does not return value on all code paths.Normally i just say throw in the catch block, which solves the problem. But as i am implementing enterprise exception block the suggestion is to use a policy with if(rethrow) statement, which i beleive creates the warning as throw is hidden inside if statement. I can say return nothing at the end of catch but i was wondering What is the best way to get rid of the warning. Public Function SearchEscalationMails() As DataSet Try Dim dbResourcePlanning As Database = DatabaseFactory.CreateDatabase() Dim strProcName As String = "SearchMailEscalations" Dim dbSPCommand As DbCommand = dbResourcePlanning.GetStoredProcCommand (strProcName) dbResourcePlanning.ExecuteDataSet(dbSPCommand) Return dbResourcePlanning.ExecuteDataSet(dbSPCommand) Catch ex As Exception Dim bRethrow As Boolean bRethrow = ExceptionPolicy.HandleException(ex, "BusinessLayerPolicy") If (bRethrow) Then Throw End If End Try End Function -- modified at 10:49 Sunday 29th April, 2007
-
Inside of the exception nothing is returned. It might be better written like this:
dim ds as DataSet = Nothing
Try
...
ds = dbResourcePlanning.ExecuteDataSet(dbSPCommand)
...
Finally
Return ds
End TryEnd Function
Hope that helps. Ben
Hi Kubben, i think this helps, thanks for your suggestion.