HaxeFoundation / haxe-evolution

Repository for maintaining proposal for changes to the Haxe programming language
111 stars 58 forks source link

The `throws` statement #110

Closed SomeoneSom closed 1 year ago

SomeoneSom commented 1 year ago

Rendered proposal

Simn commented 1 year ago

I've always found this annoying to deal with in Java, but I suppose that comes from my rather non-corporate attitude. I don't like having to tell a compiler twice that I'm throwing some exception, once to throw it and then once to confirm that I actually mean it. So this doesn't seam very appealing to me, but I won't let that affect my judgement on this too much.

grepsuzette commented 1 year ago

I share your point of view on why it can be useful, but don't think we should add a syntax. Most people won't use it, also having function foo() :Void throws Class complicates the signature.

I have been using @:throws(Class) function foo():Void for years (on my personal, non-java, projects). For me it's better because:

tl;dr: I don't see the need of a more specific syntax.

back2dos commented 1 year ago

Not an overly big fan of relying on exceptions so strongly, but this feels somewhat incomplete:

SomeoneSom commented 1 year ago

Are two functions with the same args and return type but differenent exceptions thrown the same or different function types?

That's a good point, making this work with function types would require some strange syntax, I am not actually sure how that would be achieved. (args) -> return -> exception could potentially work, but this seems more like a hack than an actual solution.

I have been using @:throws(Class) function foo():Void for years (on my personal, non-java, projects).

I never actually considered @:throws since it only actually does anything on the Java target, but this idea might be better suited as a new compiler meta tag (this could also work by just adding more stuff to @:throws, but then it performs different things on different targets, and moving the current @:throws to something like @:javaThrows would be a breaking change, though I have no clue how much it would actually effect).

SomeoneSom commented 1 year ago

Closing as considering this, this would be better as compiler metadata.