question

rnuryapici avatar image
0 Votes"
rnuryapici asked raw65 commented

Crash inside a try/catch block

I see 8.2K events from 1.2K users in Firebase Console for my iOS application (last 90 days). As I inspected the problem, the line where crash occurs is inside a try/catch block.
Statistically almost every user has probably seen this issue, but I never experienced any crashes while developing or trying to reproduce this crash. This crash hasn't seen in my Android application.

So, I'm wondering how is it possible to crash inside a try/catch block? Or is it possible to firebase logs non-fatal exceptions for iOS and shows as crashes?

Crashes at line 22.

 try   
 {   
     var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();   
     var settings = new JsonSerializerSettings   
     {   
         NullValueHandling = NullValueHandling.Ignore,   
         MissingMemberHandling = MissingMemberHandling.Ignore   
     };   
     response.statusCode = httpResponseMessage.StatusCode;   
     if (httpResponseMessage.IsSuccessStatusCode)   
     {   
         var result = JsonConvert.DeserializeObject<T>(jsonString, settings);   
         response.Response = JsonConvert.DeserializeObject<T>(jsonString, settings);   
     }   
     else if (httpResponseMessage.StatusCode == HttpStatusCode.BadRequest   
          || httpResponseMessage.StatusCode == HttpStatusCode.InternalServerError   
          || httpResponseMessage.StatusCode == HttpStatusCode.Forbidden   
          || httpResponseMessage.StatusCode == HttpStatusCode.ServiceUnavailable   
          || httpResponseMessage.StatusCode == HttpStatusCode.Unauthorized)   
     {   
         var error = JsonConvert.DeserializeObject<ErrorMessageModel>(jsonString, settings);   
         response.ErrorCode = error.ErrorCode;   
         response.ErrorMessage = error.ErrorMessage;   
         return response;   
     }   
       
     return response;   
 }   
 catch (JsonException)   
 {   
     return await this.PopulateResponse<T>(httpResponseMessage, true, ++count);   
 }   
 catch (Exception)   
 {   
     return response;   
 }   


Stacktrace of this crash from Firebase is below.
BaseClient line 70 corresponds that code block's line 21
BaseClient line 71 corresponds that code block's line 22

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
Crashed: tid_407

 0x10461d6a8 ut_end + 71 (BaseClient.cs:71)
 0x10461d69c ut_end + 68 (BaseClient.cs:70)
 0x1032872b0 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 4341641904
 0x10592eb54 mono_jit_runtime_invoke + 3165 (mini-runtime.c:3165)
 0x1059ea278 mono_runtime_invoke_checked + 3052 (object.c:3052)
 0x105913b04 mono_gsharedvt_constrained_call + 1429 (jit-icalls.c:1429)
 0x10328c440 wrapper_managed_to_native_object___icall_wrapper_mono_gsharedvt_constrained_call_intptr_intptr_intptr_intptr_intptr + 4341662784
 0x1031cbf94 System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_TResult_GSHAREDVT_Start_TStateMachine_GSHAREDVT_TStateMachine_GSHAREDVT_ + 4340875156
 0x10461d180 VXXXC_Services_BaseClient_PopulateResponse_T_REF_System_Net_Http_HttpResponseMessage_bool_int + 4362178944
 0x10463fb44 VXXXC_Services_Services_VehicleService__GetDefaultUserVehicled__6_MoveNext + 132 (VehicleService.cs:132)
 0x10307109c System_Runtime_CompilerServices_AsyncMethodBuilderCore_MoveNextRunner_InvokeMoveNext_object + 4339454108
 0x102ff661c System_Threading_ExecutionContext_RunInternal_System_Threading_ExecutionContext_System_Threading_ContextCallback_object_bool + 4338951708
 0x102ff641c System_Threading_ExecutionContext_Run_System_Threading_ExecutionContext_System_Threading_ContextCallback_object_bool + 4338951196
 0x103070f58 System_Runtime_CompilerServices_AsyncMethodBuilderCore_MoveNextRunner_Run + 4339453784
 0x103014498 System_Threading_Tasks_SynchronizationContextAwaitTaskContinuation__c___cctorb__7_0_object + 4339074200
 0x103eaafcc Foundation_NSAsyncSynchronizationContextDispatcher_Apply + 178 (NSAction.cs:178)
 0x1032872b0 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 4341641904
 0x10592eb54 mono_jit_runtime_invoke + 3165 (mini-runtime.c:3165)
 0x1059ea278 mono_runtime_invoke_checked + 3052 (object.c:3052)
 0x1059edadc mono_runtime_invoke + 3107 (object.c:3107)
 0x102e9a8b0 native_to_managed_trampoline_10(objc_object*, objc_selector*, _MonoMethod**, unsigned int) + 400 (registrar.m:400)
 0x102ea2e3c -[__MonoMac_NSAsyncSynchronizationContextDispatcher xamarinApplySelector] + 9890 (registrar.m:9890)
 0x195473b90 __NSThreadPerformPerform + 188
 0x19405976c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
 0x194059668 __CFRunLoopDoSource0 + 208
 0x194058960 __CFRunLoopDoSources0 + 268
 0x194052a8c __CFRunLoopRun + 824
 0x19405221c CFRunLoopRunSpecific + 600
 0x1abc1c784 GSEventRunModal + 164
 0x196a92ee8 -[UIApplication _run] + 1072
 0x196a9875c UIApplicationMain + 168
 0x103f18b18 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 4354820888
 0x103e59860 UIKit_UIApplication_Main_string___intptr_intptr + 86 (UIApplication.cs:86)
 0x103e597e4 UIKit_UIApplication_Main_string___string_string + 66 (UIApplication.cs:66)
 0x102ee76e4 VXXXC_iOS_Application_Main_string__ + 1 (<unknown>:1)
 0x1032872b0 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 4341641904
 0x10592eb54 mono_jit_runtime_invoke + 3165 (mini-runtime.c:3165)
 0x1059ea278 mono_runtime_invoke_checked + 3052 (object.c:3052)
 0x1059f04d0 mono_runtime_exec_main_checked + 5178 (object.c:5178)

dotnet-xamarin
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Post your try / catch block and your exception

0 Votes 0 ·

hi @alessandrocaliaro, I updated with the code.

0 Votes 0 ·

and which is the exception you have?

0 Votes 0 ·
Show more comments

Are you sure it's crashing on line 22? What error message are you getting? Do have any more detail?
A JsonException on line 21 could lead to a crash if line 31 also throws an exception.

0 Votes 0 ·

Because it exceeds the character limit of the comment, I added stacktrace of crash to the post.

A JsonException on line 21 could lead to a crash if line 31 also throws an exception.

@raw65, Can you explain this?




1 Vote 1 ·

If a JSonException occurs on line 21, then the catch block starting on line 29 will be invoked but the code inside the catch block is not covered by a try block so any exception that occurs there would crash the program.

As I look at your code again this seems very likely to be the case. Line 21 assumes you received a JSON response but it seems very likely that there are cases where you will not get JSON, especially in the event of an InternalServer error. Maybe as a debugging step try replacing line 31 with an alert that displays the response code and text.

0 Votes 0 ·

0 Answers