Android Question Try catch working on a device not working on another one...

pantaraf

Member
Licensed User
Longtime User
Hi,
I'm noticing a strange behaviour from the following code:

B4X:
Sub ImageView1_Click
  Try
    If(Meteo.FindLocation.Length>0) Then
      Meteo.CityName=Meteo.AreaName
      edtLoc.Text=Meteo.AreaName
      MeteoUpdate
    End If
  Catch
    If(edtLoc.Text<>"") Then
        Try
          Meteo.CityName=edtLoc.Text
          MeteoUpdate
        Catch
          'località errata o non trovata
        End Try
    End If
    'Località non trovata
  End Try
End Sub

Meteo is defined as
B4X:
Dim Meteo As ICOSWorldForecast
and properly initialized
B4X:
Meteo.Initialize("previsioni")
Meteo.ApiKey="myprivatekey ;)"

If I make this code run on a LG L5 (Android 4.0.3) it works without a problem, the first try catches the exception and jumps to the catch section. When it runs on an Eeepad Transformer (TF101 Android 4.0.3) it doesn't work as it should, the try intercepts the action but it just make the code jump to End Sub instead of the Catch section. I've cleaned the project each time I've swapped the devices in the compiler.
Any suggestions?
Thank you.
Raffaele
 

pantaraf

Member
Licensed User
Longtime User
SOLVED.
The Meteo.FindLocation.Length property doesn't throw and exception even if the ICOSWorldForecast is initialized but still Null.
So, the following code solved the weird behaviour.

B4X:
Sub ImageView1_Click
  If(Meteo.FindLocation.Length>0) Then
    Try
    Meteo.CityName=Meteo.AreaName
    edtLoc.Text=Meteo.AreaName
    MeteoUpdate
    Catch
    If(edtLoc.Text<>"") Then
      Try
        Meteo.CityName=edtLoc.Text
        MeteoUpdate
      Catch
        'località errata o non trovata
      End Try
    End If
    End Try
   End If
End Sub
 
  • Like
Reactions: eps
Upvote 0
Top