[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/23/2009 at 10:05AM PDT, ID: 24838620
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Thrown exception not being caught in C++

Asked by edc in C++ Programming Language

Hello all,
Im experiencing a strange issue.  I am building a static library, and I have an executable as a test harness that I am using to test various functionality of the library.  Below is the complete code of the test harness, (because it is small), and the function in the library which is causing the problem.  

The issue is that the exception thrown when the username is not found in the database is not caught by the catch block in the test harness.  Thus far this is the only exception that is behaving in this fashion.  Every other exception, (that I have tested so far) works as expected, (i.e. is caught by the catch block in the test harness code).  The offending lines are:

result = sqlite3_step(stmt);
if( result != SQLITE_ROW )
{
       throw MyException("Test");
}

I am using gcc (GCC) 3.4.5 (mingw-vista special) on Windows XP (SP2).

I am really stumped here.  Thanks for any help you can offer.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
Test Harness Code:
int main()
{
    try
    {
        MyServerDatabase database;
        database.CreateDatabase(NULL);
 
        database.OpenDatabase();
        MyUserData *user = new MyUserData();
        database.GetUser("jsmith", user);
    }
 
    catch( MyException e )
    {
        std::string s = e.what();
    }
 
    return 0;
}
 
/*************************************************************************************************************/
 
Library Code Function:
 
void MyServerDatabase::GetUser(std::string userName, MyUserData *user)
{
    if( !m_DatabaseIsOpen )
    {
        throw MyException("The database is not open.  Call OpenDatabase() before attempting to access data.");
    }
 
	sqlite3_stmt *stmt;
	const char *tail;
 
	std::string querySql("SELECT Id, UserName, FullName, Password, Description, State, DeviceId, Lock FROM Users WHERE UserName='" + userName + "';");
 
	int result = sqlite3_prepare_v2(m_Database, querySql.c_str(), querySql.length(), &stmt, &tail);
	if( result != SQLITE_OK )
	{
		throw MyException(sqlite3_errmsg(m_Database));
	}
 
	result = sqlite3_step(stmt);
	if( result != SQLITE_ROW )
	{
        throw MyException("Test");
	}
 
	user->SetDescription((char*)sqlite3_column_text(stmt, 4));
	user->SetFullName((char*)sqlite3_column_text(stmt, 2));
	user->SetPassword((char*)sqlite3_column_text(stmt, 3));
	user->SetDeviceId(sqlite3_column_int(stmt, 6));
	user->SetIsLocked(sqlite3_column_int(stmt, 7));
	user->SetRowIdentifier(sqlite3_column_int(stmt, 0));
	user->SetState((UserState)sqlite3_column_int(stmt, 5));
	user->SetUserName((char*)sqlite3_column_text(stmt, 1));
 
	result = sqlite3_step(stmt);
	if( result != SQLITE_DONE )
	{
		throw MyException("The database is corrupt.  Multiple users with username " + userName + " were found in the database.");
	}
 
	result = sqlite3_finalize(stmt);
	if( result != SQLITE_OK )
	{
		throw MyException(sqlite3_errmsg(m_Database));
	}
}
[+][-]10/23/09 10:20 AM, ID: 25646442

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 10:53 AM, ID: 25646713

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 10:53 AM, ID: 25646718

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 01:30 PM, ID: 25648263

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/23/09 01:31 PM, ID: 25648274

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 01:38 PM, ID: 25648336

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/23/09 01:40 PM, ID: 25648354

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 01:43 PM, ID: 25648384

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/23/09 01:43 PM, ID: 25648385

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Sign Up Now!
Solution Provided By: evilrix
Participating Experts: 3
Solution Grade: A
 
 
[+][-]10/23/09 01:47 PM, ID: 25648413

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 02:35 PM, ID: 25648892

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625