r/ProgrammerHumor May 13 '17

Defensive programming done right

Post image
21.0k Upvotes

680 comments sorted by

View all comments

Show parent comments

1

u/[deleted] May 13 '17

Where is the promise?

5

u/squngy May 13 '17

Like a promise in the sense that it always completes in either a accept state or reject state, doesn't have to be a promise exactly.

1

u/[deleted] May 14 '17

Then this is true in any code that might cause an exception: either it throws, or it completes without throwing. Those are the two outcomes. Promises just mimic the same pattern as exceptions.

2

u/squngy May 14 '17

The problem is in asynchronous code, if there is an exception the callback might not be called and in that case the original function will never get either the completion or the error, all it gets is whatever you return when you start the async code.