Listening on the error event on the window object should work (I'm assuming 
the error is thrown). I.e:

window.addEventListener('error', function (e) {
  // Not sure how to check if this is the error you're looking for (it might 
suck if it's triggered by some other runtime error).
  // Maybe a naive regex on the message text would do.
  if(thisIsTheErrorYoureLookingFor(e) {
    elmApp = Elm.Main.fullscreen(null);
  }
}

elmApp = Elm.Main.fullscreen(startingState);


Source: http://stackoverflow.com/a/13435462/1165146

Den lördag 15 oktober 2016 kl. 19:20:11 UTC+2 skrev Kevin Berridge:
>
> I'm using App.programWithFlags to initialize the state of my model from 
> local storage (as described in this blog article 
> <https://medium.com/wunder-nerds/storing-and-restoring-the-state-in-elm-0-17-94874429dc1d>).
>  
>  But when the schema of my model changes (ex: I added a new field to a 
> record type) it will correctly error out when Elm.Main.fullscreen is called 
> with error: "You are trying to initialize module `Main` with an unexpected 
> argument."
>
> I am OK with throwing away the state from local storage and starting from 
> scratch when this happens, so I tried to add a try catch in the JavaScript 
> but surprisingly (to me) the catch doesn't fire.
>
> try {
>     elmApp = Elm.Main.fullscreen(startingState);
> }
> catch (e) {
>     elmApp = Elm.Main.fullscreen(null); // this never gets called
> }
>
> Is there a way that I can catch this error?  Or do I need to use a 
> different approach?
>
> Thanks,
> Kevin
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to