Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exception Handling using catch(...) [modified]

Exception Handling using catch(...) [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelplounge
8 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vijay victory
    wrote on last edited by
    #1

    Hi Experts, I m doing a databse application using CDatabase and CRecordset classes. The Database is created dynamically using Catalog.

    _CatalogPtr m_pCatalog = NULL;
    CoInitialize(NULL);
    m_pCatalog.CreateInstance(__uuidof (Catalog));

    m_pCatalog->Create((const char *)(CString("Provider =Microsoft.Jet.OLEDB.4.0;Data Source=" + csAccessDbname)));

    I have two Queries. 1>. I have handle the exception using CDBExceptionand a general exception handler Catch(...).But for the following statement,

    UserRs.Open(CRecordset::snapshot,Sql,CRecordset::none);

    an exception occurs but could not caught by CDBException but caught in Catch(...) block. But the prbm is I couldnt understand the reason. I want to Show the Exception in Catch(...) Block. 2>. My code is as follows :

    try
    {
    UserCn.OpenEx(_T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=" + csAccessDbname + ";"),CDatabase::noOdbcDialog);
    }
    //Exception occurd here
    UserRs.Open(CRecordset::snapshot,Sql,CRecordset::none);
    }
    catch(CDBException cdb)
    {
    MessageBox(NULL,cdb.m_strError ,"fnInitFromFile_CDBException",0);
    }
    catch(CException ce)
    {
    AfxMessageBox(ce.ReportError());
    AfxMessageBox("CException..inside fnInitFromFile");
    }
    catch(...)
    { //Exception caught here
    MessageBox(NULL,"CRecordSetfailed.. ","fnInitFromFile_Exception",0);
    }

    This code works fine for my machine but on others machine. It create database and Exception is occured at UserRs.Open() statement. PLz Help me.. I m trying my all ways to solve this problem.. Thnx is advance.. waitnng for ur valuable response..

    I have never failed,I just found 1000 ways that never works. Regards, Victory.

    modified on Monday, July 6, 2009 2:28 AM

    C S 2 Replies Last reply
    0
    • V vijay victory

      Hi Experts, I m doing a databse application using CDatabase and CRecordset classes. The Database is created dynamically using Catalog.

      _CatalogPtr m_pCatalog = NULL;
      CoInitialize(NULL);
      m_pCatalog.CreateInstance(__uuidof (Catalog));

      m_pCatalog->Create((const char *)(CString("Provider =Microsoft.Jet.OLEDB.4.0;Data Source=" + csAccessDbname)));

      I have two Queries. 1>. I have handle the exception using CDBExceptionand a general exception handler Catch(...).But for the following statement,

      UserRs.Open(CRecordset::snapshot,Sql,CRecordset::none);

      an exception occurs but could not caught by CDBException but caught in Catch(...) block. But the prbm is I couldnt understand the reason. I want to Show the Exception in Catch(...) Block. 2>. My code is as follows :

      try
      {
      UserCn.OpenEx(_T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=" + csAccessDbname + ";"),CDatabase::noOdbcDialog);
      }
      //Exception occurd here
      UserRs.Open(CRecordset::snapshot,Sql,CRecordset::none);
      }
      catch(CDBException cdb)
      {
      MessageBox(NULL,cdb.m_strError ,"fnInitFromFile_CDBException",0);
      }
      catch(CException ce)
      {
      AfxMessageBox(ce.ReportError());
      AfxMessageBox("CException..inside fnInitFromFile");
      }
      catch(...)
      { //Exception caught here
      MessageBox(NULL,"CRecordSetfailed.. ","fnInitFromFile_Exception",0);
      }

      This code works fine for my machine but on others machine. It create database and Exception is occured at UserRs.Open() statement. PLz Help me.. I m trying my all ways to solve this problem.. Thnx is advance.. waitnng for ur valuable response..

      I have never failed,I just found 1000 ways that never works. Regards, Victory.

      modified on Monday, July 6, 2009 2:28 AM

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      vijay.victory wrote:

      It create database and Exception is occured at UserRs.Open() statement.

      Could you paste the exact exception details (e.g. the complete error description) ?

      Cédric Moonen Software developer
      Charting control [v2.0] OpenGL game tutorial in C++

      V 1 Reply Last reply
      0
      • C Cedric Moonen

        vijay.victory wrote:

        It create database and Exception is occured at UserRs.Open() statement.

        Could you paste the exact exception details (e.g. the complete error description) ?

        Cédric Moonen Software developer
        Charting control [v2.0] OpenGL game tutorial in C++

        V Offline
        V Offline
        vijay victory
        wrote on last edited by
        #3

        Thnk u for ur reply. But as I said, it is caught by catch(...) block and handled by me. So I dont know the Exact Exception that occrd here.. Can u tell me, How I can Display or know which Exception is caught by catch(...) block. I m confused about the situation where, It works fine on my machine but not on some others machines.. Plz Reply...

        I have never failed,I just found 1000 ways that never works. Regards, Victory.

        1 Reply Last reply
        0
        • V vijay victory

          Hi Experts, I m doing a databse application using CDatabase and CRecordset classes. The Database is created dynamically using Catalog.

          _CatalogPtr m_pCatalog = NULL;
          CoInitialize(NULL);
          m_pCatalog.CreateInstance(__uuidof (Catalog));

          m_pCatalog->Create((const char *)(CString("Provider =Microsoft.Jet.OLEDB.4.0;Data Source=" + csAccessDbname)));

          I have two Queries. 1>. I have handle the exception using CDBExceptionand a general exception handler Catch(...).But for the following statement,

          UserRs.Open(CRecordset::snapshot,Sql,CRecordset::none);

          an exception occurs but could not caught by CDBException but caught in Catch(...) block. But the prbm is I couldnt understand the reason. I want to Show the Exception in Catch(...) Block. 2>. My code is as follows :

          try
          {
          UserCn.OpenEx(_T("Driver={Microsoft Access Driver (*.mdb)};" "Dbq=" + csAccessDbname + ";"),CDatabase::noOdbcDialog);
          }
          //Exception occurd here
          UserRs.Open(CRecordset::snapshot,Sql,CRecordset::none);
          }
          catch(CDBException cdb)
          {
          MessageBox(NULL,cdb.m_strError ,"fnInitFromFile_CDBException",0);
          }
          catch(CException ce)
          {
          AfxMessageBox(ce.ReportError());
          AfxMessageBox("CException..inside fnInitFromFile");
          }
          catch(...)
          { //Exception caught here
          MessageBox(NULL,"CRecordSetfailed.. ","fnInitFromFile_Exception",0);
          }

          This code works fine for my machine but on others machine. It create database and Exception is occured at UserRs.Open() statement. PLz Help me.. I m trying my all ways to solve this problem.. Thnx is advance.. waitnng for ur valuable response..

          I have never failed,I just found 1000 ways that never works. Regards, Victory.

          modified on Monday, July 6, 2009 2:28 AM

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Note the documentation[^] - CRecordset::Open can throw exceptions of type CDBException* and CMemoryException* - i.e. POINTERS to exception objects, not exception objects. MFC throws pointers because when it was written, the Microsoft C++ compiler didn't do exceptions (not properly, at least), so MFC had its own exception handling functionality. Change your exception handlers to the code below (note the exception signature and the added exception object deletion lines) and you should be good.

          catch(CDBException* cdb)
          {
          MessageBox(NULL,cdb.m_strError ,"fnInitFromFile_CDBException",0);
          cdb->Delete();
          }
          catch(CException* ce)
          {
          AfxMessageBox(ce.ReportError());
          AfxMessageBox("CException..inside fnInitFromFile");
          ce->Delete();
          }

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          modified on Monday, July 6, 2009 5:30 AM

          V 1 Reply Last reply
          0
          • S Stuart Dootson

            Note the documentation[^] - CRecordset::Open can throw exceptions of type CDBException* and CMemoryException* - i.e. POINTERS to exception objects, not exception objects. MFC throws pointers because when it was written, the Microsoft C++ compiler didn't do exceptions (not properly, at least), so MFC had its own exception handling functionality. Change your exception handlers to the code below (note the exception signature and the added exception object deletion lines) and you should be good.

            catch(CDBException* cdb)
            {
            MessageBox(NULL,cdb.m_strError ,"fnInitFromFile_CDBException",0);
            cdb->Delete();
            }
            catch(CException* ce)
            {
            AfxMessageBox(ce.ReportError());
            AfxMessageBox("CException..inside fnInitFromFile");
            ce->Delete();
            }

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            modified on Monday, July 6, 2009 5:30 AM

            V Offline
            V Offline
            vijay victory
            wrote on last edited by
            #5

            Thanx Stuart, Actually the exception is not caught by above both catch() blocks. So I think there is no need to use Delete here. But as u said, I had use this..But problem not solved.. Plz...anyonce can tell me how to Show the Exact Exception details caught in catch(...) block. so i can find the solution as early as possible.

            I have never failed,I just found 1000 ways that never works. Regards, Victory.

            S 1 Reply Last reply
            0
            • V vijay victory

              Thanx Stuart, Actually the exception is not caught by above both catch() blocks. So I think there is no need to use Delete here. But as u said, I had use this..But problem not solved.. Plz...anyonce can tell me how to Show the Exact Exception details caught in catch(...) block. so i can find the solution as early as possible.

              I have never failed,I just found 1000 ways that never works. Regards, Victory.

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Firstly - I made a typo in my answer to you.

              vijay.victory wrote:

              Actually the exception is not caught by above both catch() blocks.

              That implies the exception is (probably) a Win32 structured exception.

              vijay.victory wrote:

              So I think there is no need to use Delete here

              You use Delete in the exception handler when you catch an exception. Yes, you most definitely need to use it in that case.

              vijay.victory wrote:

              anyonce can tell me how to Show the Exact Exception details caught in catch(...) block

              You can't in the exception handler. Full stop. What you could do is to set a breakpoint on exceptions being thrown - look in the Visual Studio Debug menu at the Exceptions menu item. That will allow you to interrupt execution (when running under the debugger) whenever an exception is thrown. So, you'll see where (and why) the exception is thrown, what type it is etc

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              V 2 Replies Last reply
              0
              • S Stuart Dootson

                Firstly - I made a typo in my answer to you.

                vijay.victory wrote:

                Actually the exception is not caught by above both catch() blocks.

                That implies the exception is (probably) a Win32 structured exception.

                vijay.victory wrote:

                So I think there is no need to use Delete here

                You use Delete in the exception handler when you catch an exception. Yes, you most definitely need to use it in that case.

                vijay.victory wrote:

                anyonce can tell me how to Show the Exact Exception details caught in catch(...) block

                You can't in the exception handler. Full stop. What you could do is to set a breakpoint on exceptions being thrown - look in the Visual Studio Debug menu at the Exceptions menu item. That will allow you to interrupt execution (when running under the debugger) whenever an exception is thrown. So, you'll see where (and why) the exception is thrown, what type it is etc

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                V Offline
                V Offline
                vijay victory
                wrote on last edited by
                #7

                Thanx Stuart Dootson , Thanx a lot.. I already tried this for my PC.. But on my machine it works fine(Where I can Debug). But on others machine , How I can Debug without the code.?? On that machine I use only the generted EXE of my application. Is their any other way? and I doubt about my Open() statement.. can u check it once and reply if any modification.. the code is at first message.. plzzzzzz ....... waitng for ur Reply..

                I have never failed,I just found 1000 ways that never works. Regards, Victory.

                1 Reply Last reply
                0
                • S Stuart Dootson

                  Firstly - I made a typo in my answer to you.

                  vijay.victory wrote:

                  Actually the exception is not caught by above both catch() blocks.

                  That implies the exception is (probably) a Win32 structured exception.

                  vijay.victory wrote:

                  So I think there is no need to use Delete here

                  You use Delete in the exception handler when you catch an exception. Yes, you most definitely need to use it in that case.

                  vijay.victory wrote:

                  anyonce can tell me how to Show the Exact Exception details caught in catch(...) block

                  You can't in the exception handler. Full stop. What you could do is to set a breakpoint on exceptions being thrown - look in the Visual Studio Debug menu at the Exceptions menu item. That will allow you to interrupt execution (when running under the debugger) whenever an exception is thrown. So, you'll see where (and why) the exception is thrown, what type it is etc

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  V Offline
                  V Offline
                  vijay victory
                  wrote on last edited by
                  #8

                  Hey guys... I find another way for the Exception Details.. The Exception is...

                  "Attempt to open a table failed - there were no columns to retrive were specified"

                  Can anyone Help Now.... plz..... I m waitng for ur valuable reply..

                  I have never failed,I just found 1000 ways that never works. Regards, Victory.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups