• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

C# Programming: Try-Catch Exception Methods

RoxburyGuy58

Smash Journeyman
Joined
Mar 23, 2008
Messages
241
Location
'Muricah
So let's say that I have a text file that has hundreds of words. I want to use a try-catch exception method that will only write out all of the five-letter words in the .txt file. This is being coded in Visual Studio 2012. I understand the basic syntax of a try-catch and what it does, but I'm not entirely sure how to approach the problem. I've been told that catching IO Exceptions would help, and I looked up a bunch of "Nearest-Neighbor Algorithms", but it's tough to understand. Help please?
 

Kimimaru

Smash Ace
Joined
Apr 19, 2012
Messages
915
Location
CA
You can just read in each line and separate the words by whitespace. You can then check each word's length in the line and see if it's 5. I'm not entirely sure why you need try and catch except for catching if the file does not exist or cannot be read.

EDIT: Exception handling is pretty slow, so you'll want to avoid it unless you absolutely need it.
 
Top Bottom