Re: Convert String To Guid

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Exception handling is expensive.... and this if this is not "exceptional",
as in....only happens in a blue moon, Id avoid the try/catch

From
http://geekswithblogs.net/jawad/archive/2005/05/20/GuidVerifier.aspx

private static Regex isGuid = new
Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F
]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);

internal static bool IsGuid(string
candidate, out Guid output)

{

bool isValid = false;

output=Guid.Empty;

if(candidate!=null)

{



if
(isGuid.IsMatch(candidate))

{


output=new Guid(candidate);


isValid = true;

}

}

return isValid;

}



rewrite that as your procedure. it avoids the try/catch, and gets the
purpose accomplished.



"Martin Moser" <MartinMoser@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D5632D53-59D9-4434-8000-B3C97722288D@xxxxxxxxxxxxxxxx
Does somebody know if there's a faster way to convert a string to a guid,
than:

Try
gID = New Guid(myString)
Catch ex As Exception
gID = Guid.Empty
End Try

even if it's not clear that the string contains a valid guid?

tia
Martin


.



Relevant Pages

  • Re: FireFox and IE respond differently to my site.
    ... try/catch is error prone on the web. ... Avoid it as if it were eval. ... Good grief, it is merely a *test case* to prove my point. ...
    (comp.lang.javascript)
  • Exceptions handling on evc++ 4.0
    ... I have had a problem using try/catch exception handling on Pocket PC ... 2003 compiling with evc++ 4.0 ... The problem is about catching CArchiveException serializing on network. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Successor to C, not C++?
    ... > Is anyone working on a successor to C that ... > embedded platforms. ... EC++ was speced without exception handling, ... That's kinda hard to avoid on this topic. ...
    (comp.lang.c)
  • Re: FireFox and IE respond differently to my site.
    ... Thomas 'PointedEars' Lahn said the following on 11/9/2007 2:47 PM: ... try/catch is error prone on the web. ... Avoid it as if it were eval. ...
    (comp.lang.javascript)
  • vs6.0 to vs2008 break in exception handling in the release versio
    ... When debugging in the ... IDE, exception handling works fine, but the release version just throws ... exceptions to the screen as if no try/catch statements are there, ...
    (microsoft.public.vc.language)