Global error catching?

13 views
Skip to first unread message

Michael Bach

unread,
Nov 5, 2020, 3:05:43 AM11/5/20
to Cappuccino & Objective-J

Dear Cappuccinorites:
I just had the situation that my application silently crashed in the browser, when the user did something I had not tested :) here:
Silent crash meant for the user that the app just became unresponsive. In the console, of course, the crash was obvious.
Question: How do I install something like a global try block around everything, which would allow me to at least put up a pertinent dialog box?
Thanks for your help, best, Michael

Mike Holman

unread,
Nov 5, 2020, 4:58:39 AM11/5/20
to objec...@googlegroups.com
There used to be a port of UKCrashReporter from Cocoa:


I don’t know if it’s still functional but the code may be a useful starting point.

Mike

Sent from my iPhone

On 5 Nov 2020, at 08:05, Michael Bach <mi...@michaelbach.de> wrote:


--
You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/db06db67-ae3f-4793-9fec-991daa25ddbdn%40googlegroups.com.

Keary Suska

unread,
Nov 5, 2020, 9:12:54 AM11/5/20
to objec...@googlegroups.com
I install a global exception handler in -applicationWillFinishLaunching. Here is my implementation:

window.addEventListener('error', function (e) {
var userInfo = @{
CPLocalizedDescriptionKey: "Sorry, but a run-time error occurred. Please take a moment to report the error.",
CPLocalizedFailureReasonErrorKey: "Your browser window will be reloaded to clear the error or CERTS may not operate correctly.",
CPLocalizedRecoverySuggestionErrorKey: LMS_REPORT_ERROR_ACTION,
LMS_ERROR_EVENT_KEY: e,
// recovery should reload browser to clear errors
CPRecoveryAttempterErrorKey: function () { window.location.reload(false); }
};
var error = [CPError errorWithDomain:CPCappuccinoErrorDomain code:LMS_RUNTIME_ERROR userInfo:userInfo];
[self presentError:error];
});

It used to catch every exception, sometimes even exceptions caused by browser plugins under Chrome. Recently, however, it doesn’t work as reliably as it used to, at least under Chrome, and I don’t recall when that began. Perhaps because the framework is overriding the global handler under certain situations. That may be why the LPCrashReporter author(s) hack the objj_msgSend implementation.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

Prof. Michael Bach

unread,
Nov 5, 2020, 12:51:00 PM11/5/20
to Keary Suska, Mike Holman, objec...@googlegroups.com
Dear Keary & Mike:

Thank you very much for providing help, pointers and code! I have now implemented and even easier version (better than nothing :) and installed it in »applicationDidFinishLaunching«.

For what it’s worth, here my simple code:
––––––––––––––––––––––
window.addEventListener('error', function (e) {
alert("An error occured, I'm sorry. Error message:\r\r" + e.message + "\r\rIf it recurs, please notify michae...@uni-freiburg.de, ideally relating the message, e.g. via a screeshot.\rI will look into it and endeavour to provide a fix.\r\rOn “Close”, the window will reload and you can retry.");
window.location.reload(false);
});
––––––––––––––––––––––

Thanks & best, Michael
--
Prof. Michael Bach <https://michaelbach.de>

Reply all
Reply to author
Forward
0 new messages