David Ferguson wrote: > > Consider > StreamReader.ReadLine() for example. It returns null if you are at > the end of the stream. It would not be as convenient to use 'in its > typical application' if it threw an exception.
Reading the EOL value is not an exceptional situation. It is an unexceptional situation. Passing invalid parameters into the Substring function is an exceptional situation. So, it rightly throws an exception. In the particular use-case you are describing (specifically, the combined use of IndexOf and Substring), then you clearly do not want an exception to be thrown. Just because your particular aggregation of .Net framework methods shouldn't throw an exception doesn't mean that everyone else should not have exceptions for other situations. If you find yourself placing the same code all over the place, that's a good clue you need to refactor your code. In your situation, you probably want a little helper function: ---- public static string ReadToDelimit(string s, string delimit) { string x=string.empty; try { x = s.Substring(0, s.IndexOf(delimit) ).Trim().ToUpper(); } catch(Exception) {} return x; } ---- Richard You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.