You anticipated the need to turn off a callback, since you added the ability, certainly you cannot expect to have imagined all possible reasons people might want to do it? The suggested option makes it simpler to do so, just as it does for settimer
What you ask is not what I had in mind, but sure, in a script I might present the user with the option to not show any further error dialogs (by turning off the current callback, enabling another one, eg (e)=>1
), and perhaps I'd do so after the first occurance, or maybe after the 37th.
What I actually had in mind, was that I'd might want to set an onerror func
at the start of a (probably complex) function, using a closure to clean up in case there was an error. Meaning I do not need to store a reference to the closure in the closure, which reduces the risk that I forget to break circular references.
That being said, I'm not sure I'd actually do this, since an error in an interrupting thread would need to be considered, to avoid premature clean up. For onerror
to be used this way, I'd prefer if you could specify the callback to be thread specific, eg, onerror Func, Addremove := 1, ThreadSpecific := 0
. Perhaps ThreadSpecific
could be: -1
to remove when thread finishes but call from interrupting threads on error, 0
not thread specific, and 1
to only call in the current thread (then remove when thread finishes). I imagine that could be useful, but maybe true / false
is enough (i.e., not threadspecific / only call in this thread).
With the other thread
in mind, I also think some might find it useful to allow the onerror
callback to return a value, indicating that the thread should continue, without displaying the default dialog. Eg, return 0
to call the next function or show the default error dialog, 1
suppress and exit thread, -1
suppress and continue thread (error handled).