Exception Handling


Exception handling is discussed in Chapter 13, “Errors and Exceptions.” This is extremely similar among all three languages. All these languages use try/catch/finally for handling exceptions, and the throw keyword to create an exception:

  // C# public void Method(Object o) {    if (o == null)       throw new ArgumentException("Error"); } public void Foo() {    try    {      Method(null);    }    catch (ArgumentException ex)    { }    catch (Exception ex)    { }    finally    { } } // C++/CLI public:    void Method(Object^ o)    {       if (o == nullptr)          throw gcnew ArgumentException("Error");    }    void Foo()    {       try       {          Method(nullptr);       }       catch (ArgumentException^ ex)       { }       catch (Exception^ ex)       { }       finally       { }    } ' Visual Basic Public Sub Method(ByVal o As Object)    If o = Nothing Then       Throw New ArgumentException("Error") End Sub Public Sub Foo()    Try       Method(Nothing)    Catch ex As ArgumentException       '    Catch ex As Exception       '    Finally       '    End Try End Sub 




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net