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

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Language/try_catch&amp;diff=1901&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Language/try_catch&amp;diff=1901&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</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;Версия 14:21, 25 мая 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://www.cppe.ru/index.php?title=C%2B%2B/Language/try_catch&amp;diff=1902&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Language/try_catch&amp;diff=1902&amp;oldid=prev"/>
				<updated>2010-05-25T10:28:08Z</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 types of exceptions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void XHandler(int test){&lt;br /&gt;
   try {&lt;br /&gt;
      if(test==0) throw test;&lt;br /&gt;
      if(test==1) throw &amp;quot;a&amp;quot;;&lt;br /&gt;
      if(test==2) throw 123.23;&lt;br /&gt;
   }catch(...){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught one.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
int main(void){&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   XHandler(0);&lt;br /&gt;
   XHandler(1);&lt;br /&gt;
   XHandler(2);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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 By Non Const Reference==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;exception&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void readIntegerFile(const string&amp;amp; fileName, vector&amp;lt;int&amp;gt;&amp;amp; dest)&lt;br /&gt;
{&lt;br /&gt;
  ifstream istr;&lt;br /&gt;
  int temp;&lt;br /&gt;
  istr.open(fileName.c_str());&lt;br /&gt;
  if (istr.fail()) {&lt;br /&gt;
    throw exception();&lt;br /&gt;
  }&lt;br /&gt;
  while (istr &amp;gt;&amp;gt; temp) {&lt;br /&gt;
    dest.push_back(temp);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
int main(int argc, char** argv)&lt;br /&gt;
{&lt;br /&gt;
  vector&amp;lt;int&amp;gt; myInts;&lt;br /&gt;
  const string fileName = &amp;quot;IntegerFile.txt&amp;quot;;&lt;br /&gt;
  try {&lt;br /&gt;
    readIntegerFile(fileName, myInts);&lt;br /&gt;
  } catch (exception&amp;amp; e) {&lt;br /&gt;
    cerr &amp;lt;&amp;lt; &amp;quot;Unable to open file &amp;quot; &amp;lt;&amp;lt; fileName &amp;lt;&amp;lt; endl;&lt;br /&gt;
    exit (1);&lt;br /&gt;
  }&lt;br /&gt;
  for (size_t i = 0; i &amp;lt; myInts.size(); i++) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; myInts[i] &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return (0);&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 By Value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;exception&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void readIntegerFile(const string&amp;amp; fileName, vector&amp;lt;int&amp;gt;&amp;amp; dest)&lt;br /&gt;
{&lt;br /&gt;
  ifstream istr;&lt;br /&gt;
  int temp;&lt;br /&gt;
  istr.open(fileName.c_str());&lt;br /&gt;
  if (istr.fail()) {&lt;br /&gt;
    throw exception();&lt;br /&gt;
  }&lt;br /&gt;
  while (istr &amp;gt;&amp;gt; temp) {&lt;br /&gt;
    dest.push_back(temp);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
int main(int argc, char** argv)&lt;br /&gt;
{&lt;br /&gt;
  vector&amp;lt;int&amp;gt; myInts;&lt;br /&gt;
  const string fileName = &amp;quot;IntegerFile.txt&amp;quot;;&lt;br /&gt;
  try {&lt;br /&gt;
    readIntegerFile(fileName, myInts);&lt;br /&gt;
  } catch (exception e) {&lt;br /&gt;
    cerr &amp;lt;&amp;lt; &amp;quot;Unable to open file &amp;quot; &amp;lt;&amp;lt; fileName &amp;lt;&amp;lt; endl;&lt;br /&gt;
    exit (1);&lt;br /&gt;
  }&lt;br /&gt;
  for (size_t i = 0; i &amp;lt; myInts.size(); i++) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; myInts[i] &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return (0);&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 char pointer type exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void XHandler(void)&lt;br /&gt;
 {&lt;br /&gt;
   try {&lt;br /&gt;
      throw &amp;quot;hello&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
   catch(char *) {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught char * inside XHandler.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
      throw;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
 {&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   try {&lt;br /&gt;
      XHandler();&lt;br /&gt;
    }&lt;br /&gt;
   catch(char *) &lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught char * inside main.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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 different types of exception==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void XHandler(int test) throw(){&lt;br /&gt;
   if(test==0)&lt;br /&gt;
     throw test;&lt;br /&gt;
   if(test==1)&lt;br /&gt;
     throw &amp;quot;a&amp;quot;;&lt;br /&gt;
   if(test==2)&lt;br /&gt;
     throw 123.23;&lt;br /&gt;
}&lt;br /&gt;
int main(void){&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   try{&lt;br /&gt;
      XHandler(0);                  // try passing 1 and 2 for different responses&lt;br /&gt;
   }catch(int i){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught an integer.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }catch(char c){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught a character.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }catch(double d){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught a double.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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 from a function==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void XHandler(int test) throw(int, char, double){&lt;br /&gt;
   if(test==0) throw test;&lt;br /&gt;
   if(test==1) throw &amp;quot;a&amp;quot;;&lt;br /&gt;
   if(test==2) throw 123.23;&lt;br /&gt;
}&lt;br /&gt;
int main(void){&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   try {&lt;br /&gt;
      XHandler(0);                  // try passing 1 and 2 for different responses&lt;br /&gt;
    }&lt;br /&gt;
   catch(int i) {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught an integer.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
   catch(char c) {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught a character.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
   catch(double d) {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught a double.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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 int type exception in a function==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void XHandler(int test){&lt;br /&gt;
   try {&lt;br /&gt;
      if(test) throw test;&lt;br /&gt;
   }catch(int i){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught exception #: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
int main(void){&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   XHandler(1);&lt;br /&gt;
   XHandler(2);&lt;br /&gt;
   XHandler(0);&lt;br /&gt;
   XHandler(3);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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 more than one type of exceptions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void XHandler(int test){&lt;br /&gt;
   try {&lt;br /&gt;
      if(test==0) throw test;&lt;br /&gt;
      if(test==1) throw &amp;quot;a&amp;quot;;&lt;br /&gt;
      if(test==2) throw 123.23;&lt;br /&gt;
   }catch(int i){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught an integer.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }catch(...){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught one.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
int main(void){&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   XHandler(0);&lt;br /&gt;
   XHandler(1);&lt;br /&gt;
   XHandler(2);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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;
==Checking for a divide-by-zero exception.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::cin;&lt;br /&gt;
using std::endl;&lt;br /&gt;
class DivideByZeroException {&lt;br /&gt;
public:&lt;br /&gt;
   DivideByZeroException()&lt;br /&gt;
      : message( &amp;quot;attempted to divide by zero&amp;quot; ) { }&lt;br /&gt;
   const char *what() const { return message; }&lt;br /&gt;
private:&lt;br /&gt;
   const char *message;&lt;br /&gt;
};&lt;br /&gt;
double quotient( int numerator, int denominator )&lt;br /&gt;
{&lt;br /&gt;
   if ( denominator == 0 )&lt;br /&gt;
      throw DivideByZeroException();&lt;br /&gt;
   return static_cast&amp;lt; double &amp;gt; ( numerator ) / denominator;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   int number1, number2;&lt;br /&gt;
   double result;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter two integers (end-of-file to end): &amp;quot;;&lt;br /&gt;
   while ( cin &amp;gt;&amp;gt; number1 &amp;gt;&amp;gt; number2 ) {&lt;br /&gt;
      try {&lt;br /&gt;
         result = quotient( number1, number2 );&lt;br /&gt;
         cout &amp;lt;&amp;lt; &amp;quot;The quotient is: &amp;quot; &amp;lt;&amp;lt; result &amp;lt;&amp;lt; endl;&lt;br /&gt;
      }&lt;br /&gt;
      catch ( DivideByZeroException ex ) { &lt;br /&gt;
         cout &amp;lt;&amp;lt; &amp;quot;Exception occurred: &amp;quot; &amp;lt;&amp;lt; ex.what() &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;\nEnter two integers (end-of-file to end): &amp;quot;;&lt;br /&gt;
   } &lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&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;
==Code block of try...catch==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(void){&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Start&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   try {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Inside try block.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Still inside try block.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }catch(int i){&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Caught an exception--value is: &amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
      cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;&lt;br /&gt;
   }&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;End&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;
==Finally catch all Exceptions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include  &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include  &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void foo()&lt;br /&gt;
{&lt;br /&gt;
   int  i, j;&lt;br /&gt;
   i = 14;&lt;br /&gt;
   j = 15;&lt;br /&gt;
}&lt;br /&gt;
void call_foo()&lt;br /&gt;
{&lt;br /&gt;
   int  k;&lt;br /&gt;
   k  = 12;&lt;br /&gt;
   foo();&lt;br /&gt;
}&lt;br /&gt;
void call_foo2()&lt;br /&gt;
{&lt;br /&gt;
   double  x = 1.3;&lt;br /&gt;
   throw (x);&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   try {&lt;br /&gt;
      call_foo();  //foo exitted with i and j destroyed&lt;br /&gt;
      call_foo2();&lt;br /&gt;
   }&lt;br /&gt;
   catch (char* message)&lt;br /&gt;
   {&lt;br /&gt;
      cerr &amp;lt;&amp;lt; message &amp;lt;&amp;lt; endl;&lt;br /&gt;
      exit(1);&lt;br /&gt;
   }&lt;br /&gt;
   catch(int n) { cout &amp;lt;&amp;lt; &amp;quot;\ncaught it &amp;quot; &amp;lt;&amp;lt; n &amp;lt;&amp;lt; endl; }&lt;br /&gt;
   catch( ... )      &lt;br /&gt;
   {&lt;br /&gt;
      cerr &amp;lt;&amp;lt; &amp;quot;THAT&amp;quot;S ALL FOLKS.&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
      abort();&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;
== Localize a try/catch to a function.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
void myFunction(int test)&lt;br /&gt;
{&lt;br /&gt;
  try{&lt;br /&gt;
    if( test ) &lt;br /&gt;
       throw test;&lt;br /&gt;
  }catch(int i) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Caught Exception #: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Start\n&amp;quot;;&lt;br /&gt;
  myFunction(1);&lt;br /&gt;
  myFunction(2);&lt;br /&gt;
  myFunction(0);&lt;br /&gt;
  myFunction(3);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;End&amp;quot;;&lt;br /&gt;
  return 0;&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;
==Use multiple catch statements. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
void myFunction(int test) &lt;br /&gt;
{ &lt;br /&gt;
  try{ &lt;br /&gt;
    if(test) &lt;br /&gt;
       throw test; // throw int &lt;br /&gt;
    else &lt;br /&gt;
       throw &amp;quot;Value is zero&amp;quot;; // throw char * &lt;br /&gt;
  } &lt;br /&gt;
  catch(int i) { &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Caught One!  Ex. #: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
  } &lt;br /&gt;
  catch(char *str) { &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Caught a string: &amp;quot;; &lt;br /&gt;
    cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
  } &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;start\n&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  myFunction(1); &lt;br /&gt;
  myFunction(2); &lt;br /&gt;
  myFunction(0); &lt;br /&gt;
  myFunction(3); &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;end&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  return 0; &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;
==Using Multiple catch Statements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void myFunction(int test)&lt;br /&gt;
{&lt;br /&gt;
  try{&lt;br /&gt;
    if(test) throw test;&lt;br /&gt;
    else throw &amp;quot;Value is zero&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  catch(int i) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Caught Exception #: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  catch(const char *str) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Caught a string: &amp;quot;;&lt;br /&gt;
    cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Start\n&amp;quot;;&lt;br /&gt;
  myFunction(1);&lt;br /&gt;
  myFunction(2);&lt;br /&gt;
  myFunction(0);&lt;br /&gt;
  myFunction(3);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;End&amp;quot;;&lt;br /&gt;
  return 0;&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>