Android Question Try/Catch Program Speed

Discussion in 'Android Questions' started by daniedb, Jun 11, 2015.

  1. daniedb

    daniedb Active Member Licensed User

    Hi Guys (Mainly for Erel)

    I have a Arduino sending a huge Serial string via Bluetooth to my Application. Sometime the string came though crappy, so I start implementing Try/Catch after I Parse the various Fields from the string.
    So currently I'm parsing about 55 variables (so 55 try/catch) in my funtion.
    Will this slowdown my Program, or any other negative effects
    Thanks
    Danie
     
  2. Troberg

    Troberg Well-Known Member Licensed User

    There will be a small slowdown, of course, but not the massive performance hits that you get in, for example C#. I also assume that the Catch (which is the most "expensive" bit) is only used on bad data, which hopefully occurs seldom.

    That said, I usually make data validation without Try-Catch, instead relying on code that checks if it's a meaningful value. That allows me to handle errors in a more intelligent way, depending on what's wrong, and also allows me to catch errors which Try-Catch wouldn't. Say, for example, that we have an integer specifying weekday, with valid values 0-6. Try-Catch would Catch if you got an "M", but it wouldn't catch if someone sent you a 7.
     
    lemonisdead likes this.
  3. daniedb

    daniedb Active Member Licensed User

    Thanks Troberg,
     
Loading...