Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Function does not return value on all code paths [modified]

Function does not return value on all code paths [modified]

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pradeep Shamarao
    wrote on last edited by
    #1

    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

    K G 2 Replies Last reply
    0
    • P Pradeep Shamarao

      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

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      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 Try

      End Function

      Hope that helps. Ben

      P 1 Reply Last reply
      0
      • P Pradeep Shamarao

        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

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        If you don't rethrow the exception, you have to return something:

        If (bRethrow) Then
        Throw
        Else
        Return Nothing
        End If

        --- single minded; short sighted; long gone;

        1 Reply Last reply
        0
        • K kubben

          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 Try

          End Function

          Hope that helps. Ben

          P Offline
          P Offline
          Pradeep Shamarao
          wrote on last edited by
          #4

          Hi Kubben, i think this helps, thanks for your suggestion.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups