Redis tests - how to catch RuntimeException

I’ve made this little test app for @Kem_Tekinay 's awesome Redis module. It just shows the Redis status and lets you run commands to “execute” from a text field:

I have a Try/Catch setup to catch things like formatting errors. If I take out one of the quotes in the example string; Set "Butch “John” - notice the missing quote after Butch, it will raise a M_Redis.Redis_MTCException (or the like) which I catch and display in a messagebox but it still throws an unhandled RuntimeException. How do I handle that?

What does your code do after the messagebox?

The return after the Redis catch is just there because i dont understand how catching an exception and dealing with it properly works.

Try
  var r as new Redis_MTC(App.RedisPassword,App.RedisAddress,App.RedisPort)
  var result as Boolean=r.Execute(txtRedisCommand.Text)
  if result then
    txtRedisCommandResult.Text=txtRedisCommand.Text+":  "+str(result)
    txtRedisCommand.Text=""
  else
    var s as string = txtRedisCommandResult.Text
    txtRedisCommandResult.Text="Error in command: "+txtRedisCommand.Text+":  "+str(result)+_
    EndOfLine + txtRedisCommandResult.Text
    txtRedisCommand.TextColor=Color.Red
  end if
Catch error as RuntimeException
  MessageBox(error.Message)
Catch error as M_Redis.RedisException
  MessageBox(error.Message)
  return
End Try

This code you posted - where is it? in an event handler, a method, or what? If the code is in an event handler, that will be all that handler does. If in a method, then you just return to the caller.

What is the unhandled exception that you get? You seem to have rather a lot of code in the Try - the exception you get could be anywhere within that. I would try to narrow it down.

Thanks Tim, its in a button action, so yeah I should move it out. I know the error(s) are coming from the redis.execute because i do see it along with the message about the missing or unbalanced quote. I catch that fine but then it seems to be throwing UnhandledRuntime exceptions - going up the line. First it raises a Redis Exception form Kem’s module, then a RE from same during a method .MaybeSend, then it raises the RE to the main event? So thats why I hthought if I returned that Redis catch it should not keep raising the RE. I changed the code to:

var r as new Redis_MTC(App.RedisPassword,App.RedisAddress,App.RedisPort)
var result as Boolean
Try
result=r.Execute(txtRedisCommand.Text)
Catch error as RuntimeException
MessageBox(error.Message)
Catch error as M_Redis.RedisException
MessageBox(error.Message)
return
End Try

if result then
txtRedisCommandResult.Text=txtRedisCommand.Text+": “+str(result)
txtRedisCommand.Text=”"
else
var s as string = txtRedisCommandResult.Text
txtRedisCommandResult.Text="Error in command: “+txtRedisCommand.Text+”: "+str(result)+_
EndOfLine + txtRedisCommandResult.Text
txtRedisCommand.TextColor=Color.Red
end if

What is the runtime exception?

1 Like

Im kind of cnfused about it but the first one is raised by the Redis module as a result of the redis exception is what it looks like - thats on the .MaybeSend Method in that module and the message is the same as in the Redis one i catch. “unbalanced quotes in request”, the third one is also in the Redis module and the message is “unexpected disconnection”.

thank you for helping me talk it through @TimStreater It looks like I just had to nest the trys:

Try
Try
result=r.Execute(txtRedisCommand.Text)
Catch error as M_Redis.RedisException
MessageBox(error.Message)
return
End Try
Catch error as RuntimeException
MessageBox(error.Message)
End Try