15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OC176 ❘ ChaPTer 53 c#, visuAl bAsic, c++/cli, And f#<br />

}<br />

try<br />

{<br />

Method(null);<br />

}<br />

catch (ArgumentException ex)<br />

{ }<br />

catch (Exception ex)<br />

{ }<br />

finally<br />

{ }<br />

code snippet CSharp/ExceptionDemo.cs<br />

// C++/CLI<br />

public:<br />

void Method(Object^ o)<br />

{<br />

if (o == nullptr)<br />

throw gcnew ArgumentException("Error");<br />

}<br />

void Foo()<br />

{<br />

try<br />

{<br />

Method(nullptr);<br />

}<br />

catch (ArgumentException^ ex)<br />

{ }<br />

catch (Exception^ ex)<br />

{ }<br />

finally<br />

{ }<br />

}<br />

' Visual Basic<br />

Public Sub Method(ByVal o As Object)<br />

If o = Nothing Then<br />

Throw New ArgumentException("Error")<br />

End Sub<br />

Public Sub Foo()<br />

Try<br />

Method(Nothing)<br />

Catch ex As ArgumentException<br />

'<br />

Catch ex As Exception<br />

'<br />

Finally<br />

'<br />

End Try<br />

End Sub<br />

code snippet CPPCLI/ExceptionDemo.h<br />

code snippet VisualBasic/ExceptionDemo.vb<br />

// F#<br />

type ExceptionDemo() as this =<br />

member this.Method(o : obj) =<br />

if o = null then<br />

raise(ArgumentException("error"))<br />

member this.Foo =<br />

try<br />

try<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!