--------------------Configuration: welding - Win32 Debug--------------------
Compiling...
welding.cpp
D:\welding存入导入对话框更改过\welding.cpp(73) : error C2317: 'try' block starting on line '52' has no catch handlers
执行 cl.exe 时出错.welding.obj - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    // welding.cpp : Defines the class behaviors for the application.
    //#include "stdafx.h"
    #include "welding.h"
    #include "weldingDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    /////////////////////////////////////////////////////////////////////////////
    // CWeldingAppBEGIN_MESSAGE_MAP(CWeldingApp, CWinApp)
    //{{AFX_MSG_MAP(CWeldingApp)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG
    ON_COMMAND(ID_HELP, CWinApp::OnHelp)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CWeldingApp constructionCWeldingApp::CWeldingApp()
    {
    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
    }/////////////////////////////////////////////////////////////////////////////
    // The one and only CWeldingApp objectCWeldingApp theApp;/////////////////////////////////////////////////////////////////////////////
    // CWeldingApp initializationBOOL CWeldingApp::InitInstance()
    {
    AfxEnableControlContainer();
    //初始化COM口
    AfxOleInit();
    //连接数据库
    HRESULT hr; try
    {
    //创建Connection连接
    hr=m_cnn.CreateInstance("ADODB.Connection");
    //如果创建成功,则建立连接
    if(SUCCEEDED(hr))
    {
    //设置超时时间为20秒
    m_cnn->ConnectionTimeout=20;
    //设置游标
    m_cnn->PutCursorLocation(adUseClient);
    //打开数据库
    hr=m_cnn->Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Tieinfo;Data Source=A5C989F4558F48D","","",adModeUnknown);
    }
    } // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.#ifdef _AFXDLL
    Enable3dControls(); // Call this when using MFC in a shared DLL
    #else
    Enable3dControlsStatic(); // Call this when linking to MFC statically
    #endif CWeldingDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    } // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
    }
    int CWeldingApp::ExitInstance()
    {
    //检验数据库状态,如果已经打开则关闭数据库
    if(m_cnn->State)
    m_cnn->Close();
    //释放连接
    m_cnn.Release();
    return CWinApp::ExitInstance();
    }
      

  2.   

    try
    {
    }
    catch(...)
    {
    }
      

  3.   

    try 

    //创建Connection连接 
    hr=m_cnn.CreateInstance("ADODB.Connection"); 
    //如果创建成功,则建立连接 
    if(SUCCEEDED(hr)) 

    //设置超时时间为20秒 
    m_cnn->ConnectionTimeout=20; 
    //设置游标 
    m_cnn->PutCursorLocation(adUseClient); 
    //打开数据库 
    hr=m_cnn->Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Tieinfo;Data Source=A5C989F4558F48D","","",adModeUnknown); 


    //这里添加catch,参数也可以是你自己指定的错误类型,"..."表示捕捉所有错误
    catch(...)
    {
    //错误处理代码
    }