why {try catch} does not catch 
Author Message
 why {try catch} does not catch

That what happens: if table does not exist, exception occurs but it is not
catched, but passed to the parent :(((

What to do?

// first check if table exists and if it is, delete it

CDatabase* db = GetDatabase();

CString sql = CString("DROP TABLE ") + tempTableName;

try

{

    db->ExecuteSQL(sql);

Quote:
} catch(CDBException ex1)

{

    // could not delete temp table

    // probably it does not exist

Quote:
}



Mon, 10 Jan 2005 11:30:51 GMT  
 why {try catch} does not catch
I have always used:

    catch(CException *ex)    // notice this is a pointer
    {
    ...
    }

--
Hank Williams
Quantum Technologies, Inc.


| That what happens: if table does not exist, exception occurs but it is not
| catched, but passed to the parent :(((
|
| What to do?
|
| // first check if table exists and if it is, delete it
|
| CDatabase* db = GetDatabase();
|
| CString sql = CString("DROP TABLE ") + tempTableName;
|
| try
|
| {
|
|     db->ExecuteSQL(sql);
|
| } catch(CDBException ex1)
|
| {
|
|     // could not delete temp table
|
|     // probably it does not exist
|
| }
|
|
|



Mon, 10 Jan 2005 12:13:50 GMT  
 why {try catch} does not catch

Quote:

> That what happens: if table does not exist, exception occurs but it is not
> catched, but passed to the parent :(((

Have you tried

TRY
{

Quote:
}

CATCH_ALL(pEx)
{
Quote:
}

END_CATCH_ALL

?



Mon, 10 Jan 2005 12:39:13 GMT  
 why {try catch} does not catch

Quote:
> That what happens: if table does not exist, exception occurs but it is not
> catched, but passed to the parent :(((

Are you sure it's a CDBException object being thrown?  Also, as Hank
says, catch a pointer (or reference) to the exception, not an object.


Mon, 10 Jan 2005 12:41:53 GMT  
 why {try catch} does not catch


Wed, 18 Jun 1902 01:00:00 GMT  
 why {try catch} does not catch
I modified the code , and that's what I have now:
const char* tempTableName = "tmp_bwl_koz";

// defined elsewhere :  CDatabase* GetDatabase()   - works correctly
everywhere

BOOL MyDialog::OnInitDialog()

{

    CDialog::OnInitDialog();

    CDatabase* db = GetDatabase();

    CString sql = CString("DROP TABLE ") + tempTableName;

    // first check if table exists and if it is, delete it

    TvbModuleResourceOverride res;

    try

    {

        try

        {

            db->ExecuteSQL(sql);

        }

        catch (...)

        {

            AfxMessageBox("Yeah");

        }

    }

    catch (...)

    {

        AfxMessageBox("Yeah again!");

     }

...

Quote:
}

My application prints "Yeah", and then "Yeah again!"  (!!!!!!!!!!?????)
Wtf is going on? Major bug in VisualC++6.0? Can it be that I call it from
OnInitDialog()? Or mayby there is some global setting smth. like
"Rethrow_exception_after_it_had_been_handled=1"?


Mon, 10 Jan 2005 12:54:05 GMT  
 why {try catch} does not catch


Wed, 18 Jun 1902 01:00:00 GMT  
 why {try catch} does not catch
Quote:
> Have you tried

> TRY
> {
> }
> CATCH_ALL(pEx)
> {
> }
> END_CATCH_ALL

> ?

Yes.
The same result :((


Mon, 10 Jan 2005 12:57:04 GMT  
 why {try catch} does not catch


Wed, 18 Jun 1902 01:00:00 GMT  
 why {try catch} does not catch
I tried it in another module of my application, and it worked correctly
there!

So smth. is probably wrong with the Dialog? What can be wrong?



Mon, 10 Jan 2005 12:59:21 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Q: Why try catch cannot catch the exception

2. TRY-CATCH vs. try-catch

3. try/catch VS TRY/CATCH

4. why try/catch mechasim does not work?

5. why try/catch mechasim does not work?

6. Why try{} catch{} not working as mind.

7. Can you catch CDBExection with try-catch keyword?

8. Catch() not catching error during CDaoDatabase.Open()

9. Why No Try-Throw-Catch Support in EVT?

10. try-catch works in Debug but not Release

11. try catch does not work

12. try-catch works in Debug but not Release

 

 
Powered by phpBB® Forum Software