catchForLogging static method
void
catchForLogging(
- Widget appWidget
)
Implementation
static void catchForLogging(Widget appWidget) {
tlLogger.v('Running app widget: ${appWidget.runtimeType.toString()}');
runZonedGuarded<Future<void>>(() async {
runApp(appWidget);
}, (dynamic e, StackTrace stackTrace) {
tlLogger.v(
'Uncaught Exception: ${e.toString()}\nstackTrace: ${stackTrace.toString()}');
final Map<String, dynamic> data = {};
bool isLogException = false;
if (e is PlatformException) {
final PlatformException pe = e;
data["nativecode"] = pe.code;
data["nativemessage"] = pe.message ?? "";
data["nativestacktrace"] = pe.stacktrace ?? "";
data["message"] = e.toString();
} else if (e is TealeafException) {
final TealeafException te = e;
data["nativecode"] = te.code ?? '';
data["nativemessage"] = te.getNativeMsg ?? '';
data["nativestacktrace"] = te.getNativeDetails ?? '';
data["message"] = te.getMsg ?? '';
isLogException =
te.getMsg?.contains(TealeafException.logErrorMsg) ?? false;
} else {
String message = "";
try {
message = e.message ?? "";
} on NoSuchMethodError {
// TypeErrors, for example, do not have messages. But, let's try to
// grab any that do have messages.
tlLogger.v('No message with this type of Flutter exception');
}
data["message"] = message;
}
data["name"] = e.runtimeType.toString();
data["stacktrace"] = stackTrace.toString();
data["handled"] = false;
// Prevent recursive calls if exception message can not be processed!!
if (isLogException) {
tlLogger.v("Not logging an uncaught log exception message");
} else {
PluginTealeaf.onTlException(data: data);
}
});
}