Try{}catch (...) {}

Source: Internet
Author: User

Problem:

When you call a third-party library in your project, use the Try{}catche (...) {} statement, exception cannot be caught.

Solution:

Enabling C + + Exceptions in Project properties->c/c++-> code generation is the third option: Yes, but there is an SEH exception (/EHa) that can catch an exception. (VS2005 SP1)

Related knowledge:

1 C + + and Windows exception handling (Try,catch; __try,__finally; __try, __except)

Original address: http://shijuanfeng.blogbus.com/logs/178616871.html

2 error handling and exception handling, which one do you use

Original address: http://bbs.chinaunix.net/thread-142587-1-1.html

Usage examples:


1 Original address: http://www.doyj.com/2006/09/11/try-catch/

Write data to illegal addresses, use try catch to not catch exceptions in release mode, use __try{}__except () {} to capture

1#include"stdafx.h"2#include <vector>3#include <iostream>4#include <cstdlib>5#include <afxwin.h>6 using namespacestd;7 int_tmain (intARGC, _tchar*argdv[])8 {9 __tryTen     { Onebyte*pch; APCH = (byte*)00001234; -*PCH =6; -     } the __except (Exception_execute_handler) -     { -printf"%s","Access violation"); -     } +  -System"Pause"); +     return 0; A}
View Code

2 Original address: Http://zhidao.baidu.com/link?url= Hnbpfn6ekae-8l43ejewqb1crmzjyqxjrkzhg66ngzkdrplhhsbdwwz3um1raqiw34cbytemyqdvendazxldso0suzcuxwiyyhlkc5vojqo

Divisor cannot be a zero example

 

1#include"stdafx.h"2#include <vector>3#include <iostream>4#include <cstdlib>5 using namespacestd;6 7 voidDivision (intDividend,intdivisor)8 {9     intresult =0;Ten     if(Divisor = =0)Throw("the divisor cannot be zero"); Oneresult = dividend/Divisor; Acout<<result<<Endl; - } - int_tmain (intARGC, _tchar*argdv[]) the { -     Try -     { -Division (4,0); +         return 0; -     } +     Catch(Const Char*err_msg) A     { atcout<<err_msg<<Endl; -     } -  -  -System"Pause"); -     return 0; in}
View Code

Try{}catch (...) {}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.