Android Question try catch between for next

tufanv

Expert
Licensed User
Longtime User
Hello

I am currently using try catch for the jobdone of a httpjob.
Currently , when the error occurs error is catched but it is not going on with the next one for the for next loop.
It just cancels the process. Is there a way to use try catch so that it can continue with the next item within the loop ?

Currently using :

B4X:
try
for i = 0 to 200
lbl.texT=list.get(i)
next
catch
log(lastexception)
end try
 

Lahksman

Active Member
Licensed User
Longtime User
I would put the try catch in the for loop.
B4X:
for i = 0 to 200
    try
        lbl.texT=list.get(i)
    catch
        log(lastexception)
    end try
next
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I need a more specific example, because in the code you posted it is easy, you should write the try-catch block inside the loop:
B4X:
for i = 0 to 200
    Try
        lbl.texT=list.get(i)
    Catch
        log(lastexception)
    End Try
next

For i... cannot raise an exception.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
sorry
I wrote the code wrong here this is my code :

B4X:
If Job.JobName="allveri" Then
        If Job.Success = True Then
    
            Dim parser As JSONParser
            Dim res As String
            res = Job.GetString
            'Log(res)
            parser.Initialize(res)
            Dim root4 As List = parser.NextArray
            Dim sayi As Int=-1
            
            For h=0 To listana.Size-1
                For Each colroot As Map In root4
                    Try
                
                
                    
                        Dim price_usd As String = colroot.Get("price_usd")
                        Dim symbol As String = colroot.Get("symbol")
                        Dim last_updated As String = colroot.Get("last_updated")
                        Dim total_supply As String = colroot.Get("total_supply")
                        Dim volume_usd As String = colroot.Get("24h_volume_usd")
                        Dim price_btc As String = colroot.Get("price_btc")
                        Dim available_supply As String = colroot.Get("available_supply")
                        Dim market_cap_usd As String = colroot.Get("market_cap_usd")
                        Dim percent_change_1h As String = colroot.Get("percent_change_1h")
                        Dim percent_change_24h As String = colroot.Get("percent_change_24h")
                        Dim name As String = colroot.Get("name")
                        Dim rank As String = colroot.Get("rank")
                        Dim id As String = colroot.Get("id")
                        Dim percent_change_7d As String = colroot.Get("percent_change_7d")
                        If symbol="BTC" Then btcprice=price_usd
                    
                        If symbol = listana.Get(h) Then
                    
                                sayi=sayi+1
                                lblcoin(sayi).Text=name
                                lblusdfiyat(sayi).Text="$ " & NumberFormat2(price_usd,1,3,0,False)
                                lbl1hafta(sayi).Text="1 Hafta: % "&percent_change_7d
                                lbl1saat(sayi).Text="1 Saat: % "&percent_change_1h
                                lbldegisim(sayi).Text="% " & NumberFormat2(percent_change_24h,1,2,2,False)
                                If percent_change_24h>=0 Then
                                    
                                    lbldegisim(sayi).color = Colors.RGB(0,162,28)
                                Else
                                    lbldegisim(sayi).color = Colors.RGB(255,58,58)
                                End If
                        
                                Dim cs As CSBuilder
                                cs.Initialize
                                cs.Font(Font.CreateNew2("HelveticaNeue",14)).color(Colors.white).Append("( " ).Pop
                                cs.Font(Font.CreateFontAwesome(11)).Color(Colors.RGB(255,156,0)).Append("").Pop
                                cs.Font(Font.CreateNew2("HelveticaNeue",10)).color(Colors.white).Append(" " & NumberFormat2(price_btc,1,8,8,False)).Pop
                                cs.Font(Font.CreateNew2("HelveticaNeue",14)).Append(" )" ).Pop
                                cs.PopAll
                                lblbtcfiyat(sayi).AttributedText=cs
                    
                                iconcoin(sayi).Bitmap=LoadBitmap(File.DirAssets, id&".png")
                
                        
                            lblsil(sayi).Tag=sayi
                        End If
                
                
            
 Catch
     Log(LastException)
End Try
                
                Next
                
                
                
                
                
                
                
                
            Next

the app stops at the loading screen and doesnot continue when
iconcoin(sayi).Bitmap=LoadBitmap(File.DirAssets, id&".png")
it cant find the png file at this line for example. also some results does not have price_change_1h for example and it also crashes so icant put try catch for just the png line.
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I tried it without debug and it worked , debug stops the app so I was mistaken. Current code works good .
 
Upvote 0
Top