michaelkrauklis
Programmer
Two quick(I hope) questions.
Exception: I'm using ODBC and the CDatabase object to query a SQL Database. My problem is that when I pass SQL an invalid date my program crashes. I catch the exception but it's not any type of exception I would be expecting such as a CDBException. I catch using catch(...). And even if I don't exit in my exception handling my program dies, and dies hard. How can I tell what kind of exception is being thrown? It only happens when there is an invalid date in my dynamicly created sql insert statement. And I'd like to still know when this happens so I can log the error and have someone go in and fix the invalid dates...
Scope: I'm a bit rusty on the scope of variables when you use pointers. Here's an example:
Now has the memory for z been freed, thus making i an invalid pointer? Or, since there is something pointing to it does the memory stay in scope and I would eventually have to delete it?
This comes into play in my error handling. I want to print out the dynamicly created SQL statement in my error message but I create it inside my try, so subsequently it goes out of scope when there is an error and I break to the catch case. So I made a pointer outside the try block, then assign it to the address of the SQL statement inside the try block. In my mind the variable should be out of scope so it is just by chance that this method has worked so far because the SQL statement hasn't been written in memory. Am I right here? And if so is there a way to keep my variable in scope other than creating it outside the try block which is a bit costly in my case or copying it to another variable that is declared out of the try block?
Any help will be greatly appreciated. Sorry for the simple questions, but it's been a while since I've done C++ and I'm a bit rusty. Thanks! MY[red]enigma[/red]SELF:-9
myenigmaself@yahoo.com
Exception: I'm using ODBC and the CDatabase object to query a SQL Database. My problem is that when I pass SQL an invalid date my program crashes. I catch the exception but it's not any type of exception I would be expecting such as a CDBException. I catch using catch(...). And even if I don't exit in my exception handling my program dies, and dies hard. How can I tell what kind of exception is being thrown? It only happens when there is an invalid date in my dynamicly created sql insert statement. And I'd like to still know when this happens so I can log the error and have someone go in and fix the invalid dates...
Scope: I'm a bit rusty on the scope of variables when you use pointers. Here's an example:
Code:
int *i;
if(true){
int z=52;
i=&z;
}
This comes into play in my error handling. I want to print out the dynamicly created SQL statement in my error message but I create it inside my try, so subsequently it goes out of scope when there is an error and I break to the catch case. So I made a pointer outside the try block, then assign it to the address of the SQL statement inside the try block. In my mind the variable should be out of scope so it is just by chance that this method has worked so far because the SQL statement hasn't been written in memory. Am I right here? And if so is there a way to keep my variable in scope other than creating it outside the try block which is a bit costly in my case or copying it to another variable that is declared out of the try block?
Any help will be greatly appreciated. Sorry for the simple questions, but it's been a while since I've done C++ and I'm a bit rusty. Thanks! MY[red]enigma[/red]SELF:-9
myenigmaself@yahoo.com