<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Visual_C%2B%2B_.NET%2FStatement%2Ftry_catch</id>
		<title>Visual C++ .NET/Statement/try catch - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Visual_C%2B%2B_.NET%2FStatement%2Ftry_catch"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Visual_C%2B%2B_.NET/Statement/try_catch&amp;action=history"/>
		<updated>2026-04-30T05:26:43Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Visual_C%2B%2B_.NET/Statement/try_catch&amp;diff=3870&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Visual_C%2B%2B_.NET/Statement/try_catch&amp;diff=3870&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:02Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Visual_C%2B%2B_.NET/Statement/try_catch&amp;diff=3871&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Visual_C%2B%2B_.NET/Statement/try_catch&amp;diff=3871&amp;oldid=prev"/>
				<updated>2010-05-26T12:06:23Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Catch All exceptions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
ref class MyDerivedException : public ApplicationException{&lt;br /&gt;
public:&lt;br /&gt;
    MyDerivedException( String ^err );&lt;br /&gt;
};&lt;br /&gt;
MyDerivedException::MyDerivedException(String ^err) : ApplicationException(err){&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
ref class MyException {&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void main(){&lt;br /&gt;
    for (int i = 0; i &amp;lt; 4; i++){&lt;br /&gt;
        try{&lt;br /&gt;
            if (i == 1)&lt;br /&gt;
                throw gcnew ApplicationException(&amp;quot;\tBase Exception&amp;quot;);&lt;br /&gt;
            else if (i == 2)&lt;br /&gt;
                throw gcnew MyDerivedException(&amp;quot;\tMy Derived Exception&amp;quot;);&lt;br /&gt;
            else if (i == 3)&lt;br /&gt;
                throw gcnew MyException();&lt;br /&gt;
        }catch (ApplicationException ^e){&lt;br /&gt;
            Console::WriteLine(e-&amp;gt;Message);&lt;br /&gt;
        }catch (...){&lt;br /&gt;
            Console::WriteLine(&amp;quot;\tMy Exception&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Catch an Exception with a try/catch Block==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
#using &amp;lt;mscorlib.dll&amp;gt;&lt;br /&gt;
using namespace System;&lt;br /&gt;
void MyFunction() {&lt;br /&gt;
    int x,y,z;&lt;br /&gt;
    x = Int32::Parse(Console::ReadLine());&lt;br /&gt;
    y = Int32::Parse(Console::ReadLine());&lt;br /&gt;
    z = x/y;&lt;br /&gt;
    Console::WriteLine(z);&lt;br /&gt;
}&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
    try {&lt;br /&gt;
        MyFunction();&lt;br /&gt;
    }&lt;br /&gt;
    catch (...) {&lt;br /&gt;
        Console::WriteLine(&lt;br /&gt;
            &amp;quot;Exception. Unable to complete the operation.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
} &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Catch custom exception and then general exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
ref class MyException : Exception&lt;br /&gt;
{&lt;br /&gt;
   public:&lt;br /&gt;
    virtual property String^ Message&lt;br /&gt;
    {&lt;br /&gt;
        String^ get() override&lt;br /&gt;
        {&lt;br /&gt;
           return &amp;quot;You must supply a command-line argument.&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
int main(array&amp;lt;String^&amp;gt;^ args)&lt;br /&gt;
{&lt;br /&gt;
     try&lt;br /&gt;
     {&lt;br /&gt;
         if (args-&amp;gt;Length &amp;lt; 1)&lt;br /&gt;
         {&lt;br /&gt;
            throw gcnew MyException();&lt;br /&gt;
         }&lt;br /&gt;
         throw gcnew Exception();&lt;br /&gt;
     }&lt;br /&gt;
     catch (MyException^ e)&lt;br /&gt;
     {&lt;br /&gt;
           Console::WriteLine(&amp;quot;MyException occurred! &amp;quot; + e-&amp;gt;Message);&lt;br /&gt;
     }&lt;br /&gt;
     catch (Exception^ exception)&lt;br /&gt;
     {&lt;br /&gt;
           Console::WriteLine(&amp;quot;Unknown exception!&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Catch Exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
ref class X {};&lt;br /&gt;
ref class Y {};&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    X ^x = gcnew X;&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
         Y ^y = (Y^)x;   &lt;br /&gt;
         Console::WriteLine(&amp;quot;No Exception&amp;quot;); &lt;br /&gt;
    }&lt;br /&gt;
    catch (InvalidCastException ^e)&lt;br /&gt;
    {&lt;br /&gt;
        Console::WriteLine(&amp;quot;Invalid Cast Exception&amp;quot;);&lt;br /&gt;
        Console::WriteLine(e-&amp;gt;StackTrace);&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Catch IndexOutOfRangeException==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   int i;&lt;br /&gt;
   array&amp;lt;int&amp;gt;^ array1 = { 0, 1, 2};&lt;br /&gt;
   try&lt;br /&gt;
   {&lt;br /&gt;
      i = array1[3];&lt;br /&gt;
   }&lt;br /&gt;
   catch(IndexOutOfRangeException^ e)&lt;br /&gt;
   {&lt;br /&gt;
      Console::WriteLine( &amp;quot;{0}, {1}&amp;quot; , e-&amp;gt;ToString(), e-&amp;gt;Message);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Catch IO exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
using namespace System::IO;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   String^ filename = &amp;quot;textfile.txt&amp;quot;;&lt;br /&gt;
   try&lt;br /&gt;
   {&lt;br /&gt;
      StreamReader^ sr2 = File::OpenText(filename);&lt;br /&gt;
      String^ line;&lt;br /&gt;
      while ((line = sr2-&amp;gt;ReadLine()) != nullptr)&lt;br /&gt;
      {&lt;br /&gt;
         Console::WriteLine(line);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   catch(IOException^ e)&lt;br /&gt;
   {&lt;br /&gt;
       Console::WriteLine(&amp;quot;Exception! {0}&amp;quot;, e-&amp;gt;Message );&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Multi Exception Handling==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
ref class LevelOneException : public ApplicationException{&lt;br /&gt;
public:&lt;br /&gt;
    LevelOneException( String ^err );&lt;br /&gt;
};&lt;br /&gt;
LevelOneException::LevelOneException(String ^err) : ApplicationException(err) &lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
ref class LevelTwoException : public LevelOneException{&lt;br /&gt;
public:&lt;br /&gt;
    LevelTwoException( String ^err );&lt;br /&gt;
};&lt;br /&gt;
LevelTwoException::LevelTwoException(String ^err) : LevelOneException(err)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
void main(){&lt;br /&gt;
    for (int i = 0; i &amp;lt; 4; i++){&lt;br /&gt;
        try{&lt;br /&gt;
            if (i == 1)&lt;br /&gt;
                throw gcnew ApplicationException(&amp;quot;\tBase Exception Thrown&amp;quot;);&lt;br /&gt;
            else if (i == 2)&lt;br /&gt;
                throw gcnew LevelOneException(&amp;quot;\tLevel 1 Exception Thrown&amp;quot;);&lt;br /&gt;
            else if (i == 3)&lt;br /&gt;
                throw gcnew LevelTwoException(&amp;quot;\tLevel 2 Exception Thrown&amp;quot;);&lt;br /&gt;
        }catch (LevelTwoException ^e2){&lt;br /&gt;
            Console::WriteLine(e2-&amp;gt;Message);&lt;br /&gt;
            Console::WriteLine(&amp;quot;\tLevel 2 Exception&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        catch (LevelOneException ^e1)&lt;br /&gt;
        {&lt;br /&gt;
            Console::WriteLine(e1-&amp;gt;Message);&lt;br /&gt;
            Console::WriteLine(&amp;quot;\tLevel 1 Exception&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        catch (ApplicationException ^e)&lt;br /&gt;
        {&lt;br /&gt;
            Console::WriteLine(e-&amp;gt;Message);&lt;br /&gt;
            Console::WriteLine(&amp;quot;\tBase Exception&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Nested exception catching==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;quot;stdafx.h&amp;quot;&lt;br /&gt;
using namespace System;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   try&lt;br /&gt;
   {&lt;br /&gt;
       try&lt;br /&gt;
       {&lt;br /&gt;
           throw gcnew Exception(&amp;quot;XYZ&amp;quot;);&lt;br /&gt;
       }&lt;br /&gt;
       catch( Exception^ exception)&lt;br /&gt;
       {&lt;br /&gt;
           Console::WriteLine(&amp;quot;Inner catch&amp;quot;);&lt;br /&gt;
       }&lt;br /&gt;
       finally&lt;br /&gt;
       {&lt;br /&gt;
           Console::WriteLine(&amp;quot;Inner finally&amp;quot;);&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
   catch(Exception^ exception)&lt;br /&gt;
   {&lt;br /&gt;
        Console::WriteLine(&amp;quot;Outer catch&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
   finally&lt;br /&gt;
   {&lt;br /&gt;
        Console::WriteLine(&amp;quot;Outer finally&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>