ErrorFx: Fortran exception library

Given the current capabilities of Fortran and Fypp, an automatic error propagation upwards (as in the Serenity example), could look as follows:

Calling

@:declare_result_type(name=int_result, value_type=integer, error_type=type(fatal_error))

would generate the type

type :: int_result
  integer, allocatable :: value
  type(fatal_error), allocatable :: error
end type int_result

which then can be used to propagate the error “thrown” by the function. It works both, when the function call is embedded in an other function

function function_with_error(...) result(intres)
  type(int_res) :: intres

  integer :: ii

  @:try_assign(lhs=ii, rhs=function2_with_error(...),&
      & result_type=int_result, error=intres%error)
  print "(a,i0)", "Value obtained in the subroutine (no error thrown): ", ii
  intres%value = ii
  :

or in a subroutine:

subroutine subroutine_with_error(error)
  type(fatal_error), allocatable, intent(out) :: error

  integer :: ii
  type(int_result), allocatable :: ires

  @:try_assign(lhs=ii, rhs=function_with_error(fail=.true.),&
      & result_type=int_result, error=error)
  print "(a,i0)", "Value obtained in the subroutine (no error thrown): ", ii
  :

I’ve implemented and described that in a special branch of FxError, so it indeed works. However, to me it feels considerably less natural as in the case of the subroutines…