exceptionHandler function

void exceptionHandler({
  1. required String tag,
  2. required Exception exception,
  3. String? context = null,
  4. StackTrace? stacktrace = null,
})

Implementation

void exceptionHandler({required String tag, required Exception exception, String? context = null, StackTrace? stacktrace = null}) {
  if (kDebugMode) {
    throw exception;
  } else {
    final prefix = "[$tag]";
    final ctx = context != null ? "[C:$context]" : "";
    var logMessage = "THEOLogger$prefix$ctx - Exception happened: $exception";
    if (!THEOLogger.instance.isListening()) {
      logMessage += " - for more info, attach a logger to THEOLogger.instance!";
    }
    print(logMessage);
    THEOLogger.instance._log(exception, stacktrace);
  }
}