
Hello, I'm writing a JNI dll that can be called from a Java GUI. The java program passes a regex and a string to search. The dll function does a boost::regex_search and returns an IntArray with the results. The problem that I'm having is that bad expressions result in a crash. For instance, if the user inputs \b as the regex and 'bad' as the string, the program crashes.

On Fri, Oct 3, 2008 at 3:28 PM, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
Hello,
I'm writing a JNI dll that can be called from a Java GUI. The java program passes a regex and a string to search. The dll function does a boost::regex_search and returns an IntArray with the results. The problem that I'm having is that bad expressions result in a crash. For instance, if the user inputs \b as the regex and 'bad' as the string, the program crashes.
If the crash happens when the exception attempts to cross the DLL boundary, the only thing I can suggest is to double-check that both the DLL and the executable are compiled with the same compiler options (at least the ABI must match.) Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On Sat, 04 Oct 2008 00:28:10 +0200, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
Hello,
I'm writing a JNI dll that can be called from a Java GUI. The java program passes a regex and a string to search. The dll function does a boost::regex_search and returns an IntArray with the results. The problem that I'm having is that bad expressions result in a crash. For instance, if the user inputs \b as the regex and 'bad' as the string, the program crashes.
You must catch the exception in your C++ code and convert it to a Java exception yourself (I assume you want your Java code to catch the exception?). Boris

Java can't catch native code exceptions. The exception has to be caught in the C++ code but so far traditional exception handling isn't working. I even tried put a try/catch block around the entire function and it still crashes. On Sat, Oct 4, 2008 at 6:08 AM, Boris <boriss@web.de> wrote:
On Sat, 04 Oct 2008 00:28:10 +0200, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
Hello,
I'm writing a JNI dll that can be called from a Java GUI. The java program passes a regex and a string to search. The dll function does a boost::regex_search and returns an IntArray with the results. The problem that I'm having is that bad expressions result in a crash. For instance, if the user inputs \b as the regex and 'bad' as the string, the program crashes.
You must catch the exception in your C++ code and convert it to a Java exception yourself (I assume you want your Java code to catch the exception?).
Boris
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Sat, 04 Oct 2008 23:45:16 +0200, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
Java can't catch native code exceptions. The exception has to be caught
Yes, that's what I meant by conversion.
in the C++ code but so far traditional exception handling isn't working. I even tried put a try/catch block around the entire function and it still crashes.
You mean you can't catch the C++ exception in C++ code? Did you try it in a small console application (just to make sure the problem is not JNI-related)? Boris
[...]

It's not catching the exception in the C++ code. Could this just having something do with using the std::string class for the regex inputs? On Sat, Oct 4, 2008 at 5:37 PM, Boris <boriss@web.de> wrote:
On Sat, 04 Oct 2008 23:45:16 +0200, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
Java can't catch native code exceptions. The exception has to be caught
Yes, that's what I meant by conversion.
in
the C++ code but so far traditional exception handling isn't working. I even tried put a try/catch block around the entire function and it still crashes.
You mean you can't catch the C++ exception in C++ code? Did you try it in a small console application (just to make sure the problem is not JNI-related)?
Boris
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Sun, 05 Oct 2008 01:45:11 +0200, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
It's not catching the exception in the C++ code. Could this just having something do with using the std::string class for the regex inputs?
I've no idea why a C++ exception shouldn't be caught in C++ code. Did you try catch(...) to test if this works at least? Boris
[...]

Yes, I tried that. On Sun, Oct 5, 2008 at 6:32 AM, Boris <boriss@web.de> wrote:
On Sun, 05 Oct 2008 01:45:11 +0200, Matthew LaCrosse <mlacrosse3@gmail.com> wrote:
It's not catching the exception in the C++ code. Could this just having
something do with using the std::string class for the regex inputs?
I've no idea why a C++ exception shouldn't be caught in C++ code. Did you try catch(...) to test if this works at least?
Boris
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi, I had a similar problem a few weeks ago with catching an exception from boost::threads. It had to do with symbol visibility (I am using the gcc compiler flag -fvisibility=hidden), see http://lists.boost.org/boost-users/2008/09/40268.php (problem solved/circumvented) http://lists.boost.org/boost-users/2008/09/40270.php (additional insight) I have also seen a trac ticket regarding this issue for many parts of boost, including regex: http://svn.boost.org/trac/boost/ticket/2114 Regards, Roland Matthew LaCrosse wrote:
Yes, I tried that.
On Sun, Oct 5, 2008 at 6:32 AM, Boris <boriss@web.de <mailto:boriss@web.de>> wrote:
On Sun, 05 Oct 2008 01:45:11 +0200, Matthew LaCrosse <mlacrosse3@gmail.com <mailto:mlacrosse3@gmail.com>> wrote:
It's not catching the exception in the C++ code. Could this just having something do with using the std::string class for the regex inputs?
I've no idea why a C++ exception shouldn't be caught in C++ code. Did you try catch(...) to test if this works at least?
Boris
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org> http://lists.boost.org/mailman/listinfo.cgi/boost-users
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thank you Roland. I haven't tried compiling with gcc yet. I'm using MS Visual C++ 9.0. What I ended up doing was just writing a filter to block the invalid expression that was causing the crash. On Mon, Oct 6, 2008 at 2:16 AM, Roland Bock <rbock@eudoxos.de> wrote:
Hi,
I had a similar problem a few weeks ago with catching an exception from boost::threads. It had to do with symbol visibility (I am using the gcc compiler flag -fvisibility=hidden), see
http://lists.boost.org/boost-users/2008/09/40268.php (problem solved/circumvented) http://lists.boost.org/boost-users/2008/09/40270.php (additional insight)
I have also seen a trac ticket regarding this issue for many parts of boost, including regex: http://svn.boost.org/trac/boost/ticket/2114
Regards,
Roland
Matthew LaCrosse wrote:
Yes, I tried that.
On Sun, Oct 5, 2008 at 6:32 AM, Boris <boriss@web.de <mailto: boriss@web.de>> wrote:
On Sun, 05 Oct 2008 01:45:11 +0200, Matthew LaCrosse <mlacrosse3@gmail.com <mailto:mlacrosse3@gmail.com>> wrote:
It's not catching the exception in the C++ code. Could this just having something do with using the std::string class for the regex inputs?
I've no idea why a C++ exception shouldn't be caught in C++ code. Did you try catch(...) to test if this works at least?
Boris
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org> http://lists.boost.org/mailman/listinfo.cgi/boost-users
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi Matthew, just to be thorough: Visibility issues can also occur with MS Visual C++. It is not a "speciality" of gcc, although the command line flags might be different, of course (I wouldn't know about that). If you're compiling with visibility=hidden (or the MS equivalent), then I would expect the problem you described (not being able to catch an exception is exactly what happened to me). Not running into exceptions is also a good solution, though :-) Regards, Roland Matthew LaCrosse wrote:
Thank you Roland. I haven't tried compiling with gcc yet. I'm using MS Visual C++ 9.0.
What I ended up doing was just writing a filter to block the invalid expression that was causing the crash.
On Mon, Oct 6, 2008 at 2:16 AM, Roland Bock <rbock@eudoxos.de <mailto:rbock@eudoxos.de>> wrote:
Hi,
I had a similar problem a few weeks ago with catching an exception from boost::threads. It had to do with symbol visibility (I am using the gcc compiler flag -fvisibility=hidden), see
http://lists.boost.org/boost-users/2008/09/40268.php (problem solved/circumvented) http://lists.boost.org/boost-users/2008/09/40270.php (additional insight)
I have also seen a trac ticket regarding this issue for many parts of boost, including regex: http://svn.boost.org/trac/boost/ticket/2114
Regards,
Roland
Matthew LaCrosse wrote:
Yes, I tried that.
On Sun, Oct 5, 2008 at 6:32 AM, Boris <boriss@web.de <mailto:boriss@web.de> <mailto:boriss@web.de <mailto:boriss@web.de>>> wrote:
On Sun, 05 Oct 2008 01:45:11 +0200, Matthew LaCrosse <mlacrosse3@gmail.com <mailto:mlacrosse3@gmail.com> <mailto:mlacrosse3@gmail.com <mailto:mlacrosse3@gmail.com>>> wrote:
It's not catching the exception in the C++ code. Could this just having something do with using the std::string class for the regex inputs?
I've no idea why a C++ exception shouldn't be caught in C++ code. Did you try catch(...) to test if this works at least?
Boris
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org> <mailto:Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org>>
http://lists.boost.org/mailman/listinfo.cgi/boost-users
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org> http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org <mailto:Boost-users@lists.boost.org> http://lists.boost.org/mailman/listinfo.cgi/boost-users
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Boris
-
Emil Dotchevski
-
Matthew LaCrosse
-
Roland Bock