Error when calling System.exit in timer callback

Former Member
Former Member
Hi Guys,

I'm encountering a problem when trying to make my app exit in a timer callback.

If I implement my view delegate to exit app when pushing a button:

using Toybox.WatchUi as Ui;

class HomeDelegate extends Ui.BehaviorDelegate {

function initialize() {
BehaviorDelegate.initialize();
}

function onSelect() {
Toybox.System.exit();
}
}


The exit log looks fine:
Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Copying file.... 2% complete
Copying file.... 4% complete
Copying file.... 96% complete
Copying file.... 98% complete
Copying file.... 100% complete
File pushed successfully
Connection Finished
Closing shell and port
Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Complete
Connection Finished
Closing shell and port



But when after pushing a button I want to start a timer that exits in a timer callback:
using Toybox.WatchUi as Ui;

class HomeDelegate extends Ui.BehaviorDelegate {

function initialize() {
BehaviorDelegate.initialize();
}

function onSelect() {
var t = new Timer.Timer();
t.start(method(:dostuff), 1000, false);
}

function dostuff() {
Toybox.System.exit();
}

}


There is always an error in the log - without any specific information

Copying file.... 98% complete
Copying file.... 100% complete
File pushed successfully
Connection Finished
Closing shell and port
Found Transport: tcp
Connecting...
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Error in timer callback
Complete
Connection Finished
Closing shell and port


Can someone please help me out? What can be the cause for this error?
Is there any way around this?
  • Former Member
    Former Member
    This message is coming out because of a small issue with our error handling code. You shouldn't need to worry about the error message. The application is exiting properly.

    When Toybox.System.exit() is executed, none of the code after it will run, and internally, the VM achieves this by setting an error code that indicates the system has exited. The message you are seeing is generated from several of our callback handlers, to indicate when an application has crashed in a callback. A change was made to our simulator configuration that makes it print more messages, and it actually caused these types of messages to show up when an application exits with System.exit(). It looks like a simple fix, so we should have it corrected in a future SDK release. I don't think you will see this error report on any devices.
  • Former Member
    Former Member
    Thanks for explaining!
    Actually I do get an error log created on my Fenix 3 HR device. It only contains this message.

    I will wait for the new version and try if it's still happening.
  • This was fixed in our 2.2.5 release, so if you get a chance, give it a try and let us know if you continue to see the problem. Thanks!