Hi Nicolas, do you also have something like finally statement in java, which is always executed (except if system.exit is called)?
(I haven't have a look at haxe yet, but I am keeping an eye on it, looks really promissing.) kind regards, -m.j.milicevic -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicolas Cannasse Sent: Thursday, August 24, 2006 8:39 PM To: Open Source Flash Mailing List Subject: Re: [osflash] Enforce the use of try block... catch > 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 _______________________________________________ osflash mailing list [email protected] http://osflash.org/mailman/listinfo/osflash_osflash.org
