Wt::Dbo::ptr null dereference
Added by Jeunn Hao Chong about 9 years ago
Hi, I am wondering if there is any way to get around null dereference exception thrown when I 'find' a non-existing object. It seems that the application is exited immediately and I am looking for some way avoid this (error handling of some sort).
Replies (4)
RE: Wt::Dbo::ptr null dereference - Added by yvan vander sanden about 9 years ago
Are you sure the exception is generated by find, and not by what you do with the null ptr afterwards? I guess somwthing like this would work:
dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");
if(joe.get() != nullptr) {
// do something
}
(Untested code, but this is how you mostly handle null pointers in C.)
RE: Wt::Dbo::ptr null dereference - Added by Jeunn Hao Chong about 9 years ago
Yes it the error appears to be generated by find. The code I am using is as below:-
@
user_ = session_.find().where("oauth_id = ?").bind("unexisting_name");
if (user_.get()==nullptr){
Wt::log("info")<<"Ghost1 detected";
Wt::WApplication::instance()->redirect("error.html");
}@
and the following is the debug I got
begin transaction
select "id", "version", "name", "email", "storage", "oauth_id", "oauth_provider" from "user" where (oauth_id = ?)
[2016-May-09 10:47:00.859642] 58187 [/dashapp L0YEBj4Iu0NxN9Yc] [info] "Ghost1 detected"
rollback transaction
[2016-May-09 10:47:00.859854] 58187 [/dashapp L0YEBj4Iu0NxN9Yc] [error] "Wt: fatal error: Wt::Dbo::ptr: null dereference"
[2016-May-09 10:47:00.859886] 58187 - [info] "WebController: Removing session L0YEBj4Iu0NxN9Yc"
weird thing is the info log is outputted but the session is destroyed soon after
RE: Wt::Dbo::ptr null dereference - Added by Koen Deforche about 9 years ago
Perhaps you should "return" after the redirect?
RE: Wt::Dbo::ptr null dereference - Added by Jeunn Hao Chong about 9 years ago
Thanks Koen! Sorry for troubling you with such trivial issues.