Rxjava + Retrofit get FATAL Exception: RxCachedThreadScheduler - android

Here's the code:
Observable.combineLatest(observable1, observable2,observable3, observable4,observable5,new Function5<>())
When one or sevral observables return code = 404,I throw exception
return Observable.error(
new RxApiException(tHttpResult.getCode(), tHttpResult.getMessage()));
And I will get
FATAL EXCEPTION : RxCachedThreadScheduler-3
How to solve this problem?

You need to define how you handle errors. If no onError handler is set up for the consumer of the Observable it gets forwarded to the Uncaught Exception Handler for the executing thread instead.
On android the exception handler causes a fatal exception when triggered, closing the application.
Either define a way that error should be handled or use RxJavaPlugins.registerErrorHandler(...) to define how unhandled exceptions should be processed for your entire application.

Related

i use kotlin coroutines nullpointExecption but not show just crash no log

i use kotlin coroutines encounter nullpointExecption but not show me just crashed no log to print
i code like this:
val job = GlobalScope.launch(Dispatchers.IO) {
val files = File(path).listFiles(videoFileFilter)
Log.d("yanghua", "${files.size}")
for (file in files) {
Log.d("yanghua", file.absolutePath)
}
}
the files is null because there no file matched,than files.size is nullpoint exception,but app crashed but not show me the exception,
and I use thread instead,it will be crash too but show me where the Exception,like this
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.huayang.localplayer/com.huayang.localplayer.FileExplorActivity}: java.lang.NullPointerException: Attempt to get length of null array
I don't know why? Anybody knows?

Log Non-fatal errors on Crashlytics

On iOS it's possible to use recordError(error) to log non-fatal errors on Crashlytics but apparently this feature is not available for Android.
The only alternative I found is to use logException(e).
I manage errors on my app and I want to log when specifics errors codes are returned. So, on Crashlytics I'd like the non-fatal errors to be referenced by the errorCode. But using the logException(e) method, errors are referenced by the method where logException(e) has been called.
How can I do that?
What I do in order to report a non-fatal issue is to log an exception using the following code (remember you can throw any subclass of Exception):
Crashlytics.logException(new Exception("My custom error message"));
You can also use Crashlytics below features to provide more information.
 Logging Non-Fatal Events:
try {
myMethodThatThrows();
} catch (Exception e) {
Crashlytics.logException(e);
// handle your exception here!
}
 Add some more messages:
Crashlytics.log(int priority, String tag, String msg);
Crashlytics.log("Higgs-Boson detected! Bailing out...");
Also you can provide some user information:
void Crashlytics.setUserIdentifier(String identifier);
void Crashlytics.setUserName(String name);
void Crashlytics.setUserEmail(String email);
For those who have migrated from Fabric-Crashlytics SDK to Firebase-Crashlytics SDK, the new way of logging non-critical exceptions or exceptions which have been caught in a try-catch block is this -
FirebaseCrashlytics.getInstance().recordException(e)
To add additional data fields to the crash report you can key-value pairs before logging the exception like this
val crashlytics = FirebaseCrashlytics.getInstance()
crashlytics.setCustomKey("position", 1)
crashlytics.setCustomKey("marker_mode", "hidden")
crashlytics.setCustomKey("direction_shown", true)
To add some log messages,
FirebaseCrashlytics.getInstance().log("Reached breakpoint 2")
As per the latest version of Crashlytics library 2.9.2 .. You can log non-fatal exception through this code
Firebase.crashlytics.recordException(e)

What are the list of Android specific exceptions?

I know some of exceptions are thrown by Android framework. Like ActivityNotFoundException, WindowManager.BadTokenException.
But i am not aware of all other exceptions which are specific to android framework.
Can anybody list possible Android framework specific exceptions with a small description. Or suggest me blogs information which contains the required information.
http://developer.android.com/reference/java/lang/Exception.html
I think here you can find it, "Known Indirect Subclasses", totally 224 exceptions.
Only choose the one started by "Android", here are about 72 exceptions, these should be the list
android.content.ActivityNotFoundException
android.util.AndroidRuntimeException
android.accounts.AuthenticatorException
android.os.BadParcelableException
android.util.Base64DataException
android.hardware.camera2.CameraAccessException
android.database.CursorIndexOutOfBoundsException
android.os.DeadObjectException
android.media.DeniedByServerException
android.support.v4.app.Fragment.InstantiationException
android.opengl.GLException
android.view.InflateException
android.content.IntentFilter.MalformedMimeTypeException
android.content.IntentSender.SendIntentException
android.view.KeyCharacterMap.UnavailableException
android.security.keystore.KeyExpiredException
android.security.keystore.KeyNotYetValidException
android.security.keystore.KeyPermanentlyInvalidatedException
android.util.MalformedJsonException
android.media.MediaCodec.CodecException
android.media.MediaCodec.CryptoException
android.media.MediaDrm.MediaDrmStateException
android.media.MediaDrmResetException
android.accounts.NetworkErrorException
android.os.NetworkOnMainThreadException
android.util.NoSuchPropertyException
android.media.NotProvisionedException
android.support.v4.os.OperationCanceledException
android.content.pm.PackageManager.NameNotFoundException
android.os.ParcelFileDescriptor.FileDescriptorDetachedException
android.os.ParcelFormatException
android.net.ParseException
android.app.PendingIntent.CanceledException
android.support.v8.renderscript.RSDriverException
android.support.v8.renderscript.RSIllegalArgumentException
android.support.v8.renderscript.RSInvalidStateException
android.support.v8.renderscript.RSRuntimeException
android.content.ReceiverCallNotAllowedException
android.os.RemoteException
android.widget.RemoteViews.ActionException
android.media.ResourceBusyException
android.content.res.Resources.NotFoundException
android.database.SQLException
android.database.sqlite.SQLiteAbortException
android.database.sqlite.SQLiteAccessPermException
android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException
android.database.sqlite.SQLiteBlobTooBigException
android.database.sqlite.SQLiteCantOpenDatabaseException
android.database.sqlite.SQLiteConstraintException
android.database.sqlite.SQLiteDatabaseCorruptException
android.database.sqlite.SQLiteDatabaseLockedException
android.database.sqlite.SQLiteDatatypeMismatchException
android.database.sqlite.SQLiteDiskIOException
android.database.sqlite.SQLiteDoneException
android.database.sqlite.SQLiteException
android.database.sqlite.SQLiteFullException
android.database.sqlite.SQLiteMisuseException
android.database.sqlite.SQLiteOutOfMemoryException
android.database.sqlite.SQLiteReadOnlyDatabaseException
android.database.sqlite.SQLiteTableLockedException
android.provider.Settings.SettingNotFoundException
android.database.StaleDataException
android.view.Surface.OutOfResourcesException
android.view.SurfaceHolder.BadSurfaceTypeException
android.nfc.TagLostException
android.util.TimeFormatException
android.os.TransactionTooLargeException
android.media.UnsupportedSchemeException
android.security.keystore.UserNotAuthenticatedException
android.view.WindowManager.BadTokenException
android.view.WindowManager.LayoutParams#token
android.view.WindowManager.InvalidDisplayException
The following are the exceptions that are supported by Android:
1.) InflateException : This exception is thrown When an error conditions are occurred.
2.) Surface.OutOfResourceException: This exception is thrown When a surface is not created or resized.
3.) SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS
4.) WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.

Scala on Android with scala.concurrent.Future do not report exception on system err/out

We build an android application with Scala 2.11. We use scala.concurrent.Future for async background tasks. The problem is, that we do not see any exceptions in logcat if exceptions are thrown inside a Future block.
We already create an execution context with our own reporter:
lazy val reporter: (Throwable => Unit) = {
t =>
t.printStackTrace()
}
implicit lazy val exec = ExecutionContext.fromExecutor(
new ThreadPoolExecutor(10, 100, 5, TimeUnit.MINUTES,
new LinkedBlockingQueue[Runnable]), reporter)
Even if I set a breakpoint inside the reporter the debugger does never stop here, even if I force throwing of exceptions insde a Future {...} block.
What are we doing wrong
According to your comment it looks like you simply didn't work with Future as needed. When some exception occurred during the Future computation it is transformed into Failure case (like Failure from Try, but in async context), e.g:
scala> Future { 10 / 0 }
res21: scala.concurrent.Future[Int] = scala.concurrent.impl.Promise$DefaultPromise#24f3ffd
As you can see there is no exception thrown or printed. To handle this exception you need to use callbacks, i.e onComplete or onFailure, e.g:
scala> res21.onFailure { case error => println(s"Error: ${ error.getMessage }") }
Error: / by zero
A great intro into Futures and Duality was given by the man with psychedelic T-Shirt Erik Meijer in the coursers intro to Reactive Programming.

No crash report received in GA

I want to receive crash report in Google Analytics for my android app. I added the code :
<bool name="ga_reportUncaughtException">true</bool>
in my analytics.xml.
I'm using SDK V4. When an uncaught exception is thrown I'm not receiving any crash report in my account's property ID.
I also used the below code right after initializing tracker in my onCreate() method.
UncaughtExceptionHandler myHandler = new ExceptionReporter(resetActivityTracker,Thread.getDefaultUncaughtExceptionHandler(),this);
Thread.setDefaultUncaughtExceptionHandler(myHandler);
I get the following lines in my log
04-10 18:34:14.527: V/GAV3(19414): Thread[main,5,main]: Tracking Exception: BadTokenException (#ResetActivity$operationTask:onPreExecute:158) {main}
04-10 18:34:14.537: V/GAV3(19414): Thread[main,5,main]: Passing exception to original handler.
after which my runtime exception (i.e uncaught exception) is logged as usual
04-10 18:34:14.547: E/AndroidRuntime(19414): FATAL EXCEPTION: main .......
(error details)
What is it I'm missing in order to get crash report in my account. Can someone provide me with full code to handle uncaught exception and to display in my account?

Categories

Resources