> Hi,
>
>
> I don't know if that could be a mtasc or haxe question.
> But could there be a way to enforce a developper to use try… catch
> block like Java do.
> Eventhough exceptions are compile-time only, there is no way (IMHO) to
> force someone to handle it.
> Coudl there be a way that compiler check and complains if it's not
> handled?
The Java feature is called "checked exceptions" and has been critized a
lot for being overly used in the Java standard library. There is not
such a feature in either MTASC or haXe but there is an easy way to
somehow it by using haXe enums :
in Java:
--------
int f() throws MyException {
if( flag )
throw new MyException();
return 0;
}
void run() {
try {
int r = f();
// do something with r
} catch( MyException e ) {
// handle MyException
}
}
in haXe:
--------
enum Result<T,E> {
Value( v : T );
Exception( e : E );
}
function f() {
if( flag )
return Exception( new MyException() );
return Value(0);
}
function run() {
switch( f() ) {
case Value(r): // do something with r
case Exception(e): // handle MyExpecption
}
}
------------
The difference is that in haXe instead of using the exception mechanism,
we can return an "enum" that forces the use to "switch" and handle all
the different cases, including the exception.
Everything is entirely strictly-typed thanks to type-inference.
Hope that helps,
Nicolas
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org