Our android app have business layer which developed by c++ and deployed with swig clang and ndk23 to so libraries. Before ndk23 we have use gnu compiler and ndk15 and it works without problem if we throw exception from c++ layer android normally catch it. But ndk23 and clang when some method throw exception its crash our app. We generally hold this bussiness layer methods in try catch but its not place to the catch its crash directly our app. If anyone know reason about that please help me.
I expected to catch business expcetions in try catch but its crashes our app.
#ifndef U_BUSINESSEXCEPTION_H
#define U_BUSINESSEXCEPTION_H
#include "ExceptionBase.h"
class BusinessException :
public ExceptionBase
{
public:
#ifndef SWIG_PROTECTED
BusinessException(void) : ExceptionBase(-1, "Business_Error_{0}")
{
}
BusinessException(String errorMessageResourceKey) : ExceptionBase(-1, "Business_Error_{0}", errorMessageResourceKey)
{
}
BusinessException(String errorMessageResourceKey, List<String>* params)
{
_errorCode = -1;
_message = IApplicationContext::GetDefaulIApplicationContext()->GetStringResourceFormat(errorMessageResourceKey, params);
LOG_ERROR("%s", this->_message.c_str());
}
~BusinessException(void) throw()
{
}
virtual void SetMessage(String errorMessage)
{
this->_message = errorMessage;
}
#endif
};
#endif
I throw it in some method with like
throw new BusinessException("Test Exception");
But when i get this exception from android side with in try catch its not work at all. It’s crashing app with type uncaught exception.
Here my My_Exception.i file for swig
/* -----------------------------------------------------------------------------
* std_except.i
*
* Typemaps used by the STL wrappers that throw exceptions.
* These typemaps are used when methods are declared with an STL exception specification, such as
* size_t at() const throw (std::out_of_range);
* ----------------------------------------------------------------------------- */
%{
#include <stdexcept>
%}
namespace std
{
%ignore exception;
struct exception {};
}
%typemap(throws) BusinessException "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());n return $null;"
%typemap(throws) DBException "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());n return $null;"
%typemap(throws) DTOException "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());n return $null;"
%typemap(throws) ExceptionBase "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());n return $null;"