Details

      Description

      Currently if I write some code like this:

      for(i <- 0 to 20){
         try{
            if(isGood(i)) return i
         }catch{
            case e => {
               System.out.println("Exception occurred. Continuing")
            }
         }
      }
      

      Then the catch statement ends up catching the value returned by the return statement.

      This is deeply confusing...

      Would there be a possible workaround for this? E.g. could we declare that, by default, a pattern for an exception does not match NonLocalReturnException?

      It would at least be nice to have some prominent documentation warning users about this problem.

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -

          Baby steps: This now emits a warning.

          try x catch { case _ => }
          

          https://github.com/scala/scala/commit/cfc0e18

          Show
          Jason Zaugg added a comment - Baby steps: This now emits a warning. try x catch { case _ => } https://github.com/scala/scala/commit/cfc0e18
          Hide
          Iulian Dragos added a comment -

          The warning is a bit too eager, see my comment on the pull request.

          Show
          Iulian Dragos added a comment - The warning is a bit too eager, see my comment on the pull request.
          Show
          Adriaan Moors added a comment - https://github.com/scala/scala/pull/798
          Hide
          Jason Zaugg added a comment -

          This ticket has grander plans than a simple warning, so I'm going to leave it open.

          Show
          Jason Zaugg added a comment - This ticket has grander plans than a simple warning, so I'm going to leave it open.
          Hide
          Adriaan Moors added a comment -

          oh, sorry about that

          Show
          Adriaan Moors added a comment - oh, sorry about that

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Rob Ennals
              TracCC:
              Ismael Juma, Paul Phillips
            • Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:

                Development