How do I go back to the "try" block after catching an error?

Put the try/catch in a while loop? I'm sure there's a better way, but that's what comes to mind first.


while (!error) {

Your try/catch code

}
 
Stop them entering the wrong type of data in the first place?

If you've got to the point of processing the data. If it goes wrong. Roll back any previous processing and throw some kind of error so you can get the user to fix. Ie stop your processing.

Also its not really good practice to use error handling to test data. if you know the input should be numeric, check before doing anything that would throw the error.

Simon
 
Code:
sub1
  dim isOK boolean = false
while not isOK then
  isOK = funct1()
end While
end sub1

funct1() as boolean
try
   'bit that may fall over
  return true
catch ex as exception
  return false
end try

end func1
Just don't as you can get stuck in a loop.

Better
Code:
sub1 button_click()
  if not isRubishData(txt1.text) then
    'do processing
  else
    'Throw message at user
  end if
end sub

function isRubishData(inData) as boolean

return whatever

end function
 
Last edited:
Back
Top Bottom