I am trying to access an Infinispan Server using HotRod library in C++ because I'm not familiar with Java but I got Exception and don't know how to proceed.
The source code is:
#include "infinispan/hotrod/ConfigurationBuilder.h"
#include "infinispan/hotrod/RemoteCacheManager.h"
#include "infinispan/hotrod/RemoteCache.h"
#include <iostream>
#include <string>
int main(int argc, char **argv) {
infinispan::hotrod::ConfigurationBuilder cb;
cb.addServer().host("192.168.1.1").port(11222);
infinispan::hotrod::RemoteCacheManager cm(cb.build());
infinispan::hotrod::RemoteCache<std::string, std::string> cache = cm.getCache<std::string, std::string>("dCache");
cm.start();
std::cout << cache.size() << std::endl;
cm.stop();
return 0;
}
and what I got is:
terminate called after throwing an instance of 'infinispan::hotrod::HotRodClientException'
what(): scala.MatchError: 24 (of class java.lang.Byte)
Aborted
ps. GDB backtrace indicates the error is occurred on the line of std::cout << cache.size() << std::endl;.
C++ client version 8.0.0 uses by default the Hotrod protocol VERSION_24, that it's too new for Infinispan 6.0.0.
Try to configure VERSION_13 this way:
cb.addServer().host("192.168.1.1").port(11222).protocolVersion(Configuration::PROTOCOL_VERSION_13);
I don't know HotRod C++ and I don't know if it's the cause of your exception but, according this page,
the RemoteCacheManager constructors, by default, start the manager; so, the following cm.start() it's a second start (?).
In this example I see that the manager is created without starting it, so...
Suggestion: try with
infinispan::hotrod::RemoteCacheManager cm(cb.build(), false);
Related
Here is my program:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
int main()
{
std::string hash = crypt("asd123","$2a$13$IP4FT4gf123I5bT6o4123123123123nbEXFqo.Oa123");
std::cout << hash;
}
Running this causes the error
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
Aborted (core dumped)
but if I remove the $ from the salt it runs fine.
The error message tells you that crypt returns a nullpointer for the given arguments. Most likely that's its way to signal failure. You need to check for that.
You can find out more about crypt by (1) finding documentation of the function, and (2) reading it.
For example, you can google “unistd crypt”.
And it so happens that the documentation specifies the valid set of characters you can use, in a nice table.
#include <iostream>
#include <thread>
int main()
{
std::thread th([] { std::cout << "Hello, World\n"; });
th.join();
}
This is all I have and it causes a runtime error. Why is that? I'm using GCC 4.8 (Ideone).
The error from ideone is:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Which means you need to be compiling with -pthread as already suggested by #Praetorian.
The code runs fine in Visual Studio 2012.
From Linux I know that in case a C++ program throws an exception, the exception type and message are printed on the terminal while the program dies. On mac, however, the only thing you get is:
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
Of course I could run the program in a debugger, but that's usually much more overhead just to see the exception type and message.
Is there any way to enable exception type and message printing on mac with any magic command?
Edit: I know what the correct way is to handle such situations with exception handling. It is more out of curiosity to find out whether the linux behavior can be reproduced on mac.
If you want to guarantee the information of a C++ exception is printed to the console you can add a try/catch block in main() like below.
#include <exception>
#include <iostream>
int main(int argc, char* argv[])
{
try { return mymain(argc, argv); }
catch(std::exception& e)
{
std::cout << "Unhandled exception thrown: " << e.what() << std::endl;
}
}
I'm just trying a few of the new C++11 features with GCC 4.7.2, though when I go to run a seg fault occurs.
$ ./a.out
Message from main.
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
I compiled with the 'beta' features of GCC, in regards to c++0x with:
g++ -std=c++11 c11.cpp
The code:
#include <future>
#include <iostream>
void called_from_async() {
std::cout << "Async call" << std::endl;
}
int main() {
//called_from_async launched in a separate thread if possible
std::future<void> result( std::async(called_from_async));
std::cout << "Message from main." << std::endl;
//ensure that called_from_async is launched synchronously
//if it wasn't already launched
result.get();
return 0;
}
I believe this happens because you have forgot to link with POSIX threads library. Just add -pthread or -lpthread to the g++ flags and the problem should go away.
If you are interested in details, this happens because C++11 runtime is resolving symbols from pthread in run-time only if you happen to use those features. So if you forgot to link, the runtime won't be able to resolve those symbols, treat your environment as if it doesn't support threads, and throw exception (which you don't catch and it aborts your application).
i am using a visual studio c++ compiler,& during my study on exception handling,i came across a number of features that can't be supported by visual c++ compiler,
like controlling the exceptions that can be thrown out of a function.
also i was unable to modify the functioning of terminate() using set_terminate() .
is it a specification too for visual c++ to modify terminate()?...& if so,then can anyone explain that why microsoft is creating these specifications in its compilers?...:-x
what do you mean you were unable to modify terminate
have you tried something like this ?
// set_terminate example
#include <iostream>
#include <exception>
#include <cstdlib>
using namespace std;
void myterminate () {
cerr << "terminate handler called\n";
abort(); // forces abnormal termination
}
int main (void) {
set_terminate (myterminate);
throw 0; // unhandled exception: calls terminate handler
return 0;
}
Don't try to run from VS. Compile and exec from command line.