Home Support Site Search Faq Register Login  
General
Re: C# equivalent of C++

Thread Starter: software projects   Started: 07-29-2010 3:33 AM   Replies: 1
  29 Jul 2010, 3:33 AM
software projects is not online. Last active: 7/29/2010 3:32:58 AM software projects

Not Ranked
Joined on 07-29-2010
Posts 1
C# equivalent of C++
What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?


Software Projects

  
  11 Aug 2010, 11:36 AM
skermes is not online. Last active: 8/11/2010 11:36:14 AM skermes

Top 10 Posts
Joined on 10-10-2008
Posts 112

SoftArtisans Technical Services

Support team
Re: C# equivalent of C++

In C# you can catch any exception with

try
{
    throw new SomeException();
}
catch
{
    // handle exception...
}

If you need to have access to the exception object during the catch block (to look at its message or wrap it in another exception to rethrow or whatever) you can do

try
{
    throw new SomeException();
}
catch (Exception ex)
{
    // handle exception...
}

Since all exception objects inherit from the Exception class that catch block will execute no matter what exception gets thrown in the try block.


  
 Page 1 of 1 (2 items)
SoftArtisans Forums » SoftArtisans Products » General » Re: C# equivalent of C++