1

I have a throwable object and I want to print its stacktrace in the logcat with an "Log.e" logging level (error). My method is throwing an exception, but the stacktrace is printed as a warning.

Here is My Code :

@Throws(RuntimeException::class)
fun throwErrorIfNotHttp (e: Throwable) {
    if (e is HttpException) {
        val code = e.code()
    } else if (e is SocketTimeoutException) {
        Log.e("time out", "time out")
    } else if (e is IOException) {
        Log.e("File error", "file error")
    } else {
       throw RuntimeException(e) // This  should appear as error
    }
}

Here is the image of exception .

enter image description here

Edit

My Extension Function:

fun <T> Observable<Response<T>>.makeRequest(
    context: Context,
    executeOnError: ((Any?) -> Unit)? = null, executeOnSuccess: (T?) -> Unit
): Disposable? {

   val disposable: Disposable = this
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            if (it.isSuccessful) {
                executeOnSuccess(it?.body())
            } else {
                val error = getExceptionFromResponse(it, context)
                 handleError(error, context)

            }
        }, {
           throwErrorIfNotHttp(it)            
        })

    return disposable

}

How can I make it to show it in error tab instead of warning tab ?

9
  • Use try catch code Commented Jun 14, 2019 at 8:39
  • I don't want to catch exception , I want app to get crash and crash report to be shown in error tab instead of as warning . Commented Jun 14, 2019 at 8:42
  • Do you mean something like this stackoverflow.com/a/28693384/9292949 Commented Jun 14, 2019 at 8:45
  • 3
    Looks like you have an rxjava observable of sorts that is throwing. You need to do it where you're subscribing; now you have a printStackTrace() error handler there. Commented Jun 14, 2019 at 8:47
  • 1
    @NicolaGallazzi That seems to work , Please add you answer , I will accept it tomorrow If there is no better way . Commented Jun 14, 2019 at 9:27

1 Answer 1

1

Try adding to your else statement

Log.e(TAG, "mymessage",e);

Whole code:

@Throws(RuntimeException::class)
fun throwErrorIfNotHttp (e: Throwable) {
    if (e is HttpException) {
            val code = e.code()
    } else if (e is SocketTimeoutException) {
            Log.e(TAG, "time out")
    } else if (e is IOException) {
            Log.e(TAG, "file error")
    } else {
      Log.e(TAG, "mymessage",e);
      throw RuntimeException(e) // This  should appear as error
    }
 }

companion object{
  val TAG = "class_tag"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.