Class: Toybox.Lang.Exception

Inherits:
Toybox.Lang.Object show all

Overview

Exception is a class that represents a thrown Exception. Custom exceptions can be created by extending this class.

Example:

Creating and throwing a new Exception class

using Toybox.Lang;
var myVar;

class myException extends Lang.Exception {
    function initialize() {
        Exception.initialize();
    }
}

if (myVar == false) {
    throw new myException();
}

Example:

Handling an Exception in a try-catch block

using Toybox.Lang;
using Toybox.System;
try {
    // Do something here
} catch (e instanceof Lang.Exception) {
    System.println(e.getErrorMessage());
}

Since:

API Level 1.0.0

Direct Known Subclasses

Ant.EncryptionInvalidSettingsException, Ant.UnableToAcquireChannelException, Ant.UnableToAcquireEncryptedChannelException, AntPlus.AntPlusNotAllowedException, Application.ObjectStoreAccessException, Properties.InvalidKeyException, Attention.BacklightOnTooLongException, Background.ExitDataSizeLimitException, Background.InvalidBackgroundTimeException, Background.MessageSizeLimitException, BluetoothLowEnergy.DevicePairException, BluetoothLowEnergy.InvalidRequestException, BluetoothLowEnergy.ProfileRegistrationException, BluetoothLowEnergy.UuidFormatException, Complications.ComplicationNotFoundException, Cryptography.InvalidBlockSizeException, Graphics.InvalidBitmapResourceException, Graphics.InvalidPaletteException, Graphics.OutOfGraphicsMemoryException, Lang.InvalidOptionsException, Lang.InvalidValueException, Lang.OperationNotAllowedException, Lang.SerializationException, Lang.StorageFullException, Lang.SymbolNotAllowedException, Lang.UnexpectedTypeException, Lang.ValueOutOfBoundsException, Sensor.TooManySensorDataListenersException, StringUtil.InvalidHexStringException, System.AppNotInstalledException, System.PreviousOperationNotCompleteException, System.UnexpectedAppTypeException, Test.AssertException, Time.RealTimeClockNotValidException, WatchUi.InvalidMenuItemTypeException, WatchUi.InvalidPointException, WatchUi.InvalidSelectableStateException

Instance Method Summary collapse

Instance Method Details

getErrorMessage() as Lang.String or Null

Get the error message for the Exception.

Returns:

  • Lang.String

    The Exception's error message, or null if no message is given

Since:

API Level 1.2.0

initialize()

Exception constructor.

Since:

API Level 1.1.2

printStackTrace() as Void

Print the stack trace of the thrown Exception.

Since:

API Level 1.1.2


Generated Sep 23, 2024, 3:32:49 PM