Skip to content

Allow a contained procedure to exit the calling procedure #337

@jacobwilliams

Description

@jacobwilliams

Here's a little thing that I have frequently wanted: some syntax to allow a contained procedure (say in a subroutine) to have a return statement that applies to the calling procedure. This is to replace something like this:

subroutine main()

! do some stuff
if (error) then
  call raise_error()
  return   !<--- have to remember to put this everywhere this routine is called
end if
! some other stuff

contains
  subroutine raise_error()
   ! do some error handling stuff
 end subroutine raise_error
end subroutine main

with:

subroutine main()

! do some stuff
if (error) call raise_error()   <---- calling this returns from main
! some other stuff

contains
  subroutine raise_error()
   ! do some error handling stuff
   return main  ! <- some kind of new syntax
 end subroutine raise_error
end subroutine main

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions