[J3] [EXTERNAL] Re: Exception handling - Golang proposal
Ondřej Čertík
ondrej at certik.us
Wed Jul 24 16:46:43 EDT 2019
On Wed, Jul 24, 2019, at 2:05 PM, Van Snyder via J3 wrote:
> On Wed, 2019-07-24 at 12:38 -0600, Ondřej Čertík via J3 wrote:
> >
> > On Wed, Jul 24, 2019, at 10:59 AM, Van Snyder via J3 wrote:
> > ...
> > > So far, nobody has proposed anything like the "try" function for
> > > Fortran.
> >
> > Actually I proposed exactly that here:
> >
> > https://mailman.j3-fortran.org/pipermail/j3/2019-February/011242.html
> >
> > while we met at the February meeting. I am not sold on any of the approaches, but I would like the committee to please seriously evaluate all these options and Pros and Cons of each.
> >
> > Ondrej
>
> I had forgotten that proposal. Does it only work for subroutines? How
> about functions? How about statements that can produce errors and have
> STAT variables? How about something like the square root of a negative
> number occurring within an assignment statement, or within an expression
> in another statement before the statement gets to its "guts?" For
> example,
>
> rewind ( int(4.51 * sqrt(x)), iostat=mystat )
>
> wherein X is negative? The "rewind" part of the "rewind" statement
> doesn't begin until after the "sqrt(x)" has failed.
Thanks Van for thinking about it.
That proposal would be just a syntactic sugar for explicitly writing the if statement by hand. So it won't catch sqrt(-1) and other errors that you couldn't already catch with the if statement. Also the interaction with the builtin functions like allocate() would have to be further discussed, there might be some issues there too.
As the Golang proposal mentions, it might not be worth doing, but I think it's a clean solution that would not preclude the compiler from doing optimizations, which many of the traditional exception mechanisms would. And so it is worth considering the Pros and Cons.
The other similar proposal for "try" is from the C++ committee, and has been already posted here:
https://mailman.j3-fortran.org/pipermail/j3/2019-February/011280.html
Here is the pdf: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
That paper is very good and highlights many of the issues and possible solutions. It has syntax for using "try" with functions. Again, let's discuss the Pros and Cons of that proposal.
Finally, Steve, I think you mentioned that you will write down your own thoughts what could be done, I would be very much interested in reading it.
Ondrej
More information about the J3
mailing list