logException static method

Future<String?> logException(
  1. String exception,
  2. bool nonfatal, [
  3. Map<String, Object>? segmentation
])

Report a handled or unhandled exception/error to Countly.

This call does not add a stacktrace automatically if it's needed, it should already be added to the exception variable

A potential use case would be to provide exception.toString()

String exception - the exception / crash information sent to the server bool nonfatal - reports if the error was fatal or not Map<String, Object> segmentation - allows to add optional segmentation

Implementation

static Future<String?> logException(String exception, bool nonfatal, [Map<String, Object>? segmentation]) async {
  if (!_instance._countlyState.isInitialized) {
    String message = '"initWithConfig" must be called before "logException"';
    log('logException, $message', logLevel: LogLevel.ERROR);
    return message;
  }
  int segCount = segmentation != null ? segmentation.length : 0;
  log('Calling "logException":[$exception] nonfatal:[$nonfatal]: with segmentation count:[$segCount]');
  List<String> args = [];
  args.add(exception);
  args.add(nonfatal.toString());
  if (segmentation != null) {
    segmentation.forEach((k, v) {
      args.add(k.toString());
      args.add(v.toString());
    });
  }
  final String? result = await _channel.invokeMethod('logException', <String, dynamic>{'data': json.encode(args)});

  return result;
}