?
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
?
529 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 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