initial run fails with exception.
amigo421 opened this issue · 3 comments
I'm newbie in rest and web services, and possibly I'm doing something wrong, please clarify.
I've just built the project successfully (WSL, Ubuntu 16.04).
and ran this. when I'm trying to request to this from browser (just opening localhost:) it raise the exception here:
`
void handler::handle_get(http_request message)
{
// ...
concurrency::streams::fstream::open_istream(U("static/index.html"), std::ios::in).then([=](concurrency::streams::istream is)
{
message.reply(status_codes::OK, is, U("text/html"));
});
//...
in pplxtasks.h
// If you are trapped here, it means an exception thrown in task chain didn't get handled.
// Please add task-based continuation to handle all exceptions coming from tasks.
// this->_M_stackTrace keeps the creation callstack of the task generates this exception.
_REPORT_PPLTASK_UNOBSERVED_EXCEPTION();
`
have any idea why this can be there?
Hi @amigo421 [ Sorry for delayed replay ]
The exception was thrown because we haven't handled any exception raised in file opening or sending datatype etc .
so please replace the handler function with new [given below ] updated handle_get function or do a pull request [i will be updating repo also with this fix ].
`
void handler::handle_get(http_request message){
ucout << message.to_string() << endl;
auto paths = http::uri::split_path(http::uri::decode(message.relative_uri().path()));
message.relative_uri().path();
concurrency::streams::fstream::open_istream(U("static/index.html"), std::ios::in).then([=](concurrency::streams::istream is)
{
message.reply(status_codes::OK, is, U("text/html"))
.then([](pplx::task<void> t)
{
try{
t.get();
}
catch(...){
//
}
});
}).then([=](pplx::task<void>t)
{
try{
t.get();
}
catch(...){
message.reply(status_codes::InternalError,U("INTERNAL ERROR "));
}
});
return;
}
And thanks for contribution :
Please let me know if you have any questions or need additional information because that's how we improve ourselves.
thank you for the fix. actually I was looking for a potential reason of the error (which is currently catched but still there) , so I've found this, my mistake, after the build , exectuable placed into Debug subfolder, and I didn't find how to set working folder in my IDE, and service couldn't find static data. fixed this, works fine.
regarding the pull request... I don't feel ready for that :) just dive into the SDK, and will can to be really helpful in 2-4 weeks only, when the basic knowledge will be there
To Know the actual reason of exception we have to debug it manually (gdb ).
but what I find out from ms-lib about that kind of exception is here ,
tasks-unhanded-exception ms-lib