How to handle errors inside a runInAction? #3707
Answered
by
mweststrate
SamuelPinho
asked this question in
Q&A
Replies: 2 comments 1 reply
-
RunInAction will throw normally, so you can catch it. ErrorBoundaries only
catch errors from rendering, not from event handling iirc.
…On Sat, 17 Jun 2023, 23:53 Samuel Monteiro, ***@***.***> wrote:
Imagine that the following code inside the runInAction, does throw an
error:
runInAction(() => {
// items variable for some reason is a "string" so it will throw an error
// when trying to access items.length
if (this.items.length === 0 && totalItemCount > 0) {
this.items = new Array(totalItemCount);
}});
Whenever an error occurs inside a runInAction, I can't catch it through a
try/catch block. I read (on MobX documentation) that this might be
something done on purpose, but I wonder how I should handle this problem
🤔
*I'm using React, so I could have an ErrorBoundary, but are there any
other solutions to that?*
—
Reply to this email directly, view it on GitHub
<#3707>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBBKGGEAFST35G2IP6LXLYRO5ANCNFSM6AAAAAAZKO3DLM>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
SamuelPinho
-
Note that items, being a string, does have a length property, so it won't
throw. And if it hadn't, it would return undefined, still not throw.
…On Sun, 18 Jun 2023, 00:16 Michel Weststrate, ***@***.***> wrote:
RunInAction will throw normally, so you can catch it. ErrorBoundaries only
catch errors from rendering, not from event handling iirc.
On Sat, 17 Jun 2023, 23:53 Samuel Monteiro, ***@***.***>
wrote:
> Imagine that the following code inside the runInAction, does throw an
> error:
>
> runInAction(() => {
> // items variable for some reason is a "string" so it will throw an error
> // when trying to access items.length
> if (this.items.length === 0 && totalItemCount > 0) {
> this.items = new Array(totalItemCount);
> }});
>
> Whenever an error occurs inside a runInAction, I can't catch it through
> a try/catch block. I read (on MobX documentation) that this might be
> something done on purpose, but I wonder how I should handle this problem
> 🤔
>
> *I'm using React, so I could have an ErrorBoundary, but are there any
> other solutions to that?*
>
> —
> Reply to this email directly, view it on GitHub
> <#3707>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAN4NBBKGGEAFST35G2IP6LXLYRO5ANCNFSM6AAAAAAZKO3DLM>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Imagine that the following code inside the
runInAction
, does throw an error:Whenever an error occurs inside a
runInAction
, I can't catch it through atry/catch
block. I read (on MobX documentation) that this might be something done on purpose, but I wonder how I should handle this problem 🤔I'm using React, so I could have an ErrorBoundary, but are there any other solutions to that?
Beta Was this translation helpful? Give feedback.
All reactions