Thread: [Cppcms-users] How to catch CPPDB errors
Brought to you by:
artyom-beilis
|
From: Marcel H. <ke...@co...> - 2013-01-23 12:36:10
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi everyone,
I'd like to know the "correct" way of handling errors in cppdb
statements.
If I do something like this:
"INSERT INTO ...." << cppdb::exec;
and there will be an error, a 500 respond will be given to the client.
Not that nice.
Next try was to catch the exception:
try {
"INSERT INTO ...." << cppdb::exec;
} catch(cppdb::cppdb_error const &e) {
//what can we do here?
}
Nice try, but cppdb_error has only the method what() and what gives me
back a char* with the error description. But there could be more than
one error in that query. That's why there are error codes. But
unfortunately every sql provider has different error codes.
Another problem with cppdb error is that the message will be
localized, so you cannot parse it.
So... what is the right way to do this?
Regards
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJQ/9kvAAoJEIROXYQnkAHpZPEQAJwW8mdI96vYANq+9Akaf65C
ykNGxrygD87HMizKQ0EPhH7qS1KuvvjYHL1z+eryEOHcILsRfvbnaHRsCAGlq6Lk
hMNrCzKeMQpcKkkYqBN4YGHzXMA+slsnQVNRQtpi7QrB3Veeg5M4Unm2tYZJenUH
HNRM1rIqqih0R2swYTZa9HXVqNkZyC9ssPo5YUtd5KK/qftv5mb5fbUgh5TIoYh6
2GqTEZJYqamMeLnUjTGkZ2EOnz07KGPlW0/PBrhYdeTIxesHIKQC3flDKvWPX8cL
CA0N4uTiAg7EF6L8CJ+CsmsEBe1wa6TSncShcqmqImM0K1ZBmFG/e1AThC80biW2
u/0A2pBfMqxdJFXDBg+/CS3ewu5A9UFX79bT0EfiZm3cLwsrLZ0bYvsC/c/aAG2v
7UfENgldy+79Rk4nUS6ZQxKbMJRmOxznsMrCrAPZl4es1VcNpfm5Drsvm6VV4sCs
0KBqN11o8rZMfLj8fWc139PwJjKGqcGW8xRjykhpWpDFwennygTBz0Hqn0BJf9Of
8nENk0bPoORGtqcgR2hf5Yp4HrM7QBP2+/hTdWNmrur+pr6tnP08U13hcBZtNlur
swTucg5WVp1GjHAmf9BZozEHhKZAY7sJZvWAZQJrbcfdYywTO9y6hERj/5sS2J2P
EmlSmccnwf7Slmw7+5n6
=CiN2
-----END PGP SIGNATURE-----
|
|
From: Artyom B. <art...@ya...> - 2013-01-23 13:50:30
|
I would suggest in general... Not get into situations where you can get a error, or at least if you expect a error catch it. What kind of errors can happen: 1. Constrain violation: * Check it before from a transaction assuming isolation * Catch at specific point - assume that the error is constraint violation. 2. Deadlock - due to colliding statements - not much to do. Or let 500 response to happen or catch a cppdb error at the root of you app hierarchy main and say (oops) 3. Connection errors or other stuff - 500 is more than reasonable - or do it what you did in 2 Now about specific errors. Probably it would be good idea to derive several sub exceptions like: cppdb::constraint_error cppdb::deadlock_error cppdb::connection_error Similarly to the current set: http://cppcms.com/sql/cppdb/classcppdb_1_1cppdb__error.html Maybe some more I can't think about them right now. But this requires some code writing and what is even more important - updating each backend and probably the most hard would be ODBC. Any volunteers? Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Marcel Hellwig <ke...@co...> >To: cpp...@li... >Sent: Wednesday, January 23, 2013 2:35 PM >Subject: [Cppcms-users] How to catch CPPDB errors > >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >Hi everyone, > >I'd like to know the "correct" way of handling errors in cppdb >statements. >If I do something like this: > "INSERT INTO ...." << cppdb::exec; >and there will be an error, a 500 respond will be given to the client. >Not that nice. >Next try was to catch the exception: > > try { > "INSERT INTO ...." << cppdb::exec; > } catch(cppdb::cppdb_error const &e) { > //what can we do here? > } > >Nice try, but cppdb_error has only the method what() and what gives me >back a char* with the error description. But there could be more than >one error in that query. That's why there are error codes. But >unfortunately every sql provider has different error codes. >Another problem with cppdb error is that the message will be >localized, so you cannot parse it. > >So... what is the right way to do this? > >Regards >-----BEGIN PGP SIGNATURE----- >Version: GnuPG v1.4.13 (GNU/Linux) >Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > >iQIcBAEBAgAGBQJQ/9kvAAoJEIROXYQnkAHpZPEQAJwW8mdI96vYANq+9Akaf65C >ykNGxrygD87HMizKQ0EPhH7qS1KuvvjYHL1z+eryEOHcILsRfvbnaHRsCAGlq6Lk >hMNrCzKeMQpcKkkYqBN4YGHzXMA+slsnQVNRQtpi7QrB3Veeg5M4Unm2tYZJenUH >HNRM1rIqqih0R2swYTZa9HXVqNkZyC9ssPo5YUtd5KK/qftv5mb5fbUgh5TIoYh6 >2GqTEZJYqamMeLnUjTGkZ2EOnz07KGPlW0/PBrhYdeTIxesHIKQC3flDKvWPX8cL >CA0N4uTiAg7EF6L8CJ+CsmsEBe1wa6TSncShcqmqImM0K1ZBmFG/e1AThC80biW2 >u/0A2pBfMqxdJFXDBg+/CS3ewu5A9UFX79bT0EfiZm3cLwsrLZ0bYvsC/c/aAG2v >7UfENgldy+79Rk4nUS6ZQxKbMJRmOxznsMrCrAPZl4es1VcNpfm5Drsvm6VV4sCs >0KBqN11o8rZMfLj8fWc139PwJjKGqcGW8xRjykhpWpDFwennygTBz0Hqn0BJf9Of >8nENk0bPoORGtqcgR2hf5Yp4HrM7QBP2+/hTdWNmrur+pr6tnP08U13hcBZtNlur >swTucg5WVp1GjHAmf9BZozEHhKZAY7sJZvWAZQJrbcfdYywTO9y6hERj/5sS2J2P >EmlSmccnwf7Slmw7+5n6 >=CiN2 >-----END PGP SIGNATURE----- > >------------------------------------------------------------------------------ >Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, >MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current >with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft >MVPs and experts. ON SALE this month only -- learn more at: >http://p.sf.net/sfu/learnnow-d2d >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
|
From: Marcel H. <ke...@co...> - 2013-01-24 11:26:22
Attachments:
signature.asc
|
Am 23.01.2013 14:50, schrieb Artyom Beilis: > I would suggest in general... > > Not get into situations where you can get a error, or at least if you > expect a error catch it. Think of registration. A Username should be unique and a email adrress should be unique too. I will not check this, because IMO this is a task for the database. > > What kind of errors can happen: > > 1. Constrain violation: > * Check it before from a transaction assuming isolation > * Catch at specific point - assume that the error is constraint > violation. > 2. Deadlock - due to colliding statements - not much to do. Or let 500 > response to happen or catch a cppdb error at the root of you > app hierarchy main and say (oops) > 3. Connection errors or other stuff - 500 is more than reasonable - or > do it what you did in 2 > > Now about specific errors. > > Probably it would be good idea to derive several sub exceptions like: > > cppdb::constraint_error > cppdb::deadlock_error > cppdb::connection_error Could be good, but there are over 100 errors that can happen while you execute a statement. But i will have a look and see what i can do. > > Similarly to the current > set: http://cppcms.com/sql/cppdb/classcppdb_1_1cppdb__error.html > > Maybe some more I can't think about them right now. > > But this requires some code writing and what is even more important - > updating each backend and probably > the most hard would be ODBC. > > Any volunteers? > > > Artyom Beilis Marcel |