[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Visual Basic 2010 - Array Size checking for a game -- Should I use TRY/CATCH or Should I use GetLength(0) + Delimiters?

Posted on 2010-11-17
4
Medium Priority
?
532 Views
Last Modified: 2012-05-10
Pretty simple question. I have a Client to Server application. Client sends a new application with user/password/etc, Server receives it seperated with a delimiter.

So let us say the delimiter is |

DataArray = Split(Data, "|")

Should I now call this:

If DataArray.GetLength(0) = 5 Then
...Do stuff
End if

Or should I do this

Try
..DoStuff
Catch
End Try


.. I want to prevent errors. I know of both but TRY/CATCH I haven't really used before, and I'm wondering if its practical here and won't be 'slow'. Application needs to be as fast as possible. Mainly to prevent someone from packet manipulation, sending one less variable to try to crash the server for example!

Also I'm wondering, what 'delimiter' can I use that someone cannot submit with a standard keyboard? Any ideas?

Thank you.
0
Comment
Question by:Valleriani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 500 total points
ID: 34159333
In the first example, you're only checking the array size.  Any other data errors go unhandled.

In the second example, any error that breaks the TRY can be ostensibly caught and dealt with.  There shouldn't be a performance hit for using TRY...CATCH
0
 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 200 total points
ID: 34159785
I think you need to use both, like this:

Try
    If DataArray.Length = 5 Then
         'do stuff
    End If
Catch

End Try

>what 'delimiter' can I use that someone cannot submit with a standard keyboard?
You can use a combination of symbols, like "~|`", which would make it hard to manipulate.

Hope it helps.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 700 total points
ID: 34159999
Exception handlers are for just that, handling "Exceptions", i.e. unexpected scenarios or things that can go wrong that you have no control over. You know you're expecting 5 elements, so you can check for that (as in your first sample) without using an exception handler.

The "Do Stuff" might benefit from and exception handler; depends what it's doing really.
0
 
LVL 12

Assisted Solution

by:omegaomega
omegaomega earned 600 total points
ID: 34161678
Hello, Valleriani,

Regarding testing vs exception handling, I concur with carl_tawn.  

Regarding a delimiter, you might want to consider using the ASCII NUL character.  I've included an example in the attached snippet.

Cheers,
Randy

Dim strTest As String = "ABC" & Chr(0) & "EFG"
        MsgBox("strTest = >>>" & strTest & "<<<")

        Dim straTest As String() = strTest.Split(Chr(0))
        MsgBox("straTest = >>>" & straTest(0) & "<<< and >>>" & straTest(1) & "<<<")

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question