nadako / haxe-coroutines

41 stars 5 forks source link

Error handling #3

Open RealyUniqueName opened 7 years ago

RealyUniqueName commented 7 years ago

Think about exception proagation scenarios.

ousado commented 6 years ago

Also think about error handling without exceptions. On some targets, especially cpp, exceptions are prohibitively expensive.

nadako commented 6 years ago

Error handling is a tricky subject indeed. Most often (e.g. js,c#,kotlin) it's implemented in coroutines by using try/catch syntax, which is a "natural" way to handle errors in the imperative code. But, even performance aside, it seems to be compromising type safety for syntax consistency in some cases. For example, if we have some API that returns Future<Either<MyResult,MyError>> (I think tink libraries do that), we know the exact type of an error we want to handle (MyError), while try/catch is a generic way to catch any error, which might be less clear and more error-prone. I'm not sure if this is a valid concern or what would be an alternative though, I guess we'll have to make some compromises here...