Re: Checking for A Blank String

Tech-Archive recommends: Fix windows errors by optimizing your registry



Göran,

"Göran Andersson" <guffa@xxxxxxxxx> schrieb:
Perhaps, but the "almost" is the reason I choose to use it over the other methods.

Why not use String.IsNullOrEmpty()? That is even more specialised for this situation.

Unfortunately this method will throw exceptions in certain scenarios

Can you give one single example where it would throw an exception?

Here is a real-world sample:

\\\
Public Module Program
Public Sub Main()
Dim f As New Foo()
f.Test = Nothing
End Sub
End Module

Public Class Foo
Private m_Test As String

Public Property Test() As String
Get
Return m_Test
End Get
Set(ByVal Value As String)
If String.IsNullOrEmpty(Value) Then
Throw _
New ArgumentNullException( _
"The 'Value' must not be 'Nothing' or an empty string." _
)
End If
m_Test = Value
End Set
End Property
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

.



Relevant Pages

  • Re: Question concerning object-oriented programming
    ... If at the end of the constructor the ... return defaults such as zero, a null string, or null. ... can also throw exceptions from methods. ... toString() in there. ...
    (comp.programming)
  • Re: Control = StrConv([Control], 3)
    ... Scott ... >> Fred- I think a list of exceptions would be best, I can only see a handful ... > Function ConvExceptionsInField(StrIn As String) As String ... > Dim strWord As String ...
    (microsoft.public.access.formscoding)
  • Re: Java 7 features
    ... indeed, get rid of checked exceptions, by making ... String foo = whatever; ... The example above explicitly initializes the String foo. ...
    (comp.lang.java.programmer)
  • Cant understand why these exceptions occur...
    ... If the command is "buffer", ... but I get exceptions if the buffer file does ... procedure LoadCache(Const cacheName: String); forward; ... if (idx < Length(files)) then ...
    (alt.comp.lang.borland-delphi)
  • Re: Neue Attribute einem Objekt =?ISO-8859-1?Q?hinzuf=FCgen?=
    ... Mit dem statsichen Typsystem hat das also nichts zu tun, sondern nur mit der Frage, ob Exceptions checked oder unchecked sein sollen. ... Für mich checked Exceptions zumindest mal was statisches und Fallen damit in die gleiche Kategorie wie das Typsystem. ... An diversen Stellen hat man code der Art "info".equalsstehen, wobei str der besagte String ist und natürlich nicht an jeder Stelle "info" als Vergleichswert herangezogen wird. ... Denn selbst wenn ich den Typ von str ändere, habe ich noch immer einen falschen Methodenaufruf drin. ...
    (de.comp.lang.java)