Crashes in throwing exceptions if code compiled in 32 bit explicity on 64 bit system
Hi LQ Memebers,
We have one shared libary which is used by Java Program using JNI. In this native libary, we throw standard exception using JNI methods,which by the way work fine. Due to some constraint, we are forced to compile this library in both modes ( 32 & 64 bit) only on 64 bit server using -m32 options. Now, the 32 bit compiled version is run on 32 bit systems and the libary crashes while attempting to throw an exception to Java program. However, if the libary is compiled on 32 bit system, it works just fine. This is my error class, #include <exception> #include <sstream> //! Base error class class Error : public std::exception { public: /*! The explicit use of this constructor is not advised. Use the GO_FAIL macro instead */ Error(const std::string& message = "") : message_(message) {}; /*! the automatically generated destructor would not have the throw specifier */ virtual ~Error() throw() {} //! returns the error message. const char* what() const throw () { return message_.c_str(); } private: std::string message_; }; Usage : throw Error("Any error"); the program fails with the following msg. terminate called after throwing an instance of 'Error' what(): Any error But if i compiled my library on 32 bit system itself, it just throws an error msg.. Any error Why is this happening ? I have also tried taking the code in debug (gdb), but the control never reaches catch block. Any help would be highly appreciated.. Thanks, Gaurav |
Any body.. pls put forth your comments..
|
Quote:
Try augmenting your code to have the following construct: Code:
... |
Are you sure that it is okay to use C++ from JNI?
|
Quote:
Anyways, Thanks for your reply. |
Quote:
Yes, That is the use of JNI, to call native libraries. In this case, the native library is written in C++. |
Thanks (back in my times JNI meant C, not C++).
|
Quote:
|
Quote:
Native.java: Code:
import java.util.*; Code:
#include <jni.h> Code:
JAVA_SRCS = Native.java |
Quote:
|
Quote:
I have been able to resolve this issue. I had some .c source files where gcc is used instead of g++ for compilation. Now, It seems that i missed to have -m32 option in the configuration of make files used for .c files and i had hided warning messages with -w option in all the makefiles. As a result, i could not see what was going on during the compilation. I have corrected these mistakes and now i can see it working fine. Thanks for you help guys. |
All times are GMT -5. The time now is 09:34 AM. |