InvocationTargetException while throwing a custom exception

Viewed 174

i am using firebase auth to login a user anonymously in my app and i want to handle the exception manually.The condition is when the sign is not completed it will throw a exception.But whenever i am running the app its just crash

Calling login method from Respository class

fun  login(mobno: String, passwrod: String) {
     auth.signInAnonymously().addOnCompleteListener {
         if(!it.isSuccessful){
            throw TypeMismatchedException(it.exception!!.message.toString())
         }
     }

Handling exception from Viewmodelclass

 fun login(mobno:String,password:String){
     try {
         repo.login(mobno,password)
     }catch (e:TypeMismatchedException){
         Log.d("exc",e.message)
     }
      catch (e: FirebaseAuthException){
          Log.d("exc",e.message)
      }
}

Logcat

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:35)
    at com.android.internal.os.ZygoteInit.main(Unknown Source:275)
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11)
    at com.android.internal.os.ZygoteInit.main(Unknown Source:275) 
 Caused by: com.smartme.student.TypeMismatchedException: This operation is restricted to administrators only.
    at com.smartme.student.viewmodel.Respository$login$1.onComplete(Respository.kt:18)
    at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
    at android.os.Handler.handleCallback(Unknown Source:2)
    at android.os.Handler.dispatchMessage(Unknown Source:4)
    at android.os.Looper.loop(Unknown Source:242)
    at android.app.ActivityThread.main(Unknown Source:98)
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11) 
    at com.android.internal.os.ZygoteInit.main(Unknown Source:275) 
0 Answers
Related