Exception handling
Handling errors is considered an essential part of MobX reactions. In fact, it provides an option to supply an error handler (onError) for autorun(), reaction(), and when(), and in the case of computed(), it will throw the error back to you any time the computed value is read. In each of these cases, MobX continues to work as expected.
Internally, MobX puts additional try-catch blocks around the execution of reactions and derivations. It will catch the errors thrown inside these blocks and propagate them back to you via the onError handlers or when a computed value is read. This behavior ensures that you can continue running your reactions and take any recovery measures inside the onError handlers.
If there is no onError ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access