Real-Serious-Games / C-Sharp-Promise

Promises library for C# for management of asynchronous operations.
MIT License
1.2k stars 149 forks source link

Should throw custom exception types instead of ApplicationException #66

Closed RoryDungan closed 6 years ago

RoryDungan commented 6 years ago

The Microsoft guidelines recommend against throwing ApplicationException, and throwing a custom type of exception would make it easier for users to distinguish between exceptions thrown by the library and their own code.

So far the only places where this would change anything is where we are attempting to resolve/reject a promise in an invalid state and when Race is called with no promises. If we merge #65 this will add one more case (where progress is updated on an already resolved/rejected promise).

sindrijo commented 6 years ago

I suggest we call it PromiseStateException, thrown whenever the state of the promise is invalid for the current operation (like resolve twice, resolve when rejected etc.) that inherits from an abstract PromiseException class. This covers most if not all of the cases, and we have a base class we can inherit from for other types of exceptions.

Race should probably just throw a ArgumentOutOfRangeExceptioninstead.

RoryDungan commented 6 years ago

I like the sound of that. In future if we need to add more types of exception they could also inherit from PromiseException.

RoryDungan commented 6 years ago

Fixed in v3.0.0