MSDN处理异常的例子

 / <script type="text/javascript"> srcString = contentarea.value; srcString = ubbReplace(srcString, 'all'); document.write(srcString); srcString = signaturearea.value; showSign(srcString); </script>/ exceptions_trycatchandthrowstatements.cpp 
// compile with: /EHsc
#include <iostream>
using namespace std;

int main()
{
    char *buf;
    try
    {
        buf = new char[512];
        if( buf == 0 )
            throw "Memory allocation failure!";
    }
    catch( char * str )
    {
        cout << "Exception raised: " << str << '/n';
    }
    // ...
    return 0;

 
 
1 楼 小土人 <script type="text/javascript">showAngel("no");</script> - 03月27日 - 11时59分 
<script type="text/javascript">if (parseInt(21251108)!=10) usezyj1.style.display="none";</script>
<script type="text/javascript"> srcString = contentarea1.value; srcString = ubbReplace(srcString, 'abgchij'); document.write(srcString); </script>// exceptions_trycatchandthrowstatements2.cpp 
// compile with: /EHsc
#include <iostream>
using namespace std;
void MyFunc( void );

class CTest {
public:
   CTest(){};
   ~CTest(){};
   const char *ShowReason() const { return "Exception in CTest class."; }
};

class CDtorDemo {
public:
   CDtorDemo();
   ~CDtorDemo();
};

CDtorDemo::CDtorDemo() {
   cout << "Constructin* **torDemo./n";
}

CDtorDemo::~CDtorDemo() {
   cout << "Destructin* **torDemo./n";
}

void MyFunc() {
   CDtorDemo D;
   cout<< "In MyFunc(). Throwing CTest exception./n";
   throw CTest();
}

int main() {
   cout << "In main./n";
   try {
       cout << "In try block, calling MyFunc()./n";
       MyFunc();
   }
   catch( CTest E ) {
       cout << "In catch handler./n";
       cout << "Caught CTest exception type: ";
       cout << E.ShowReason() << "/n";
   }
   catch( char *str )    {
       cout << "Caught some other exception: " << str << "/n";
   }
   cout << "Back in main. Execution resumes here./n";
   return 0;

  <script type="text/javascript"> srcString = signaturearea1.value; showSign(srcString); </script>
 
2 楼 小土人 <script type="text/javascript">showAngel("no");</script> - 03月27日 - 12时01分 
<script type="text/javascript">if (parseInt(21251108)!=10) usezyj2.style.display="none";</script>
<script type="text/javascript"> srcString = contentarea2.value; srcString = ubbReplace(srcString, 'abgchij'); document.write(srcString); </script>// exceptions_trycatchandthrowstatements3.cpp 
#include <iostream>
using namespace std;

void empty() throw()
{
   puts("In empty()");
}

void with_type() throw(int)
{
   puts("Will throw an int");
   throw(1);
}

int main()
{
   try {
       empty();
       with_type();
   }catch (int){
       puts("Caught an int");
   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值