Solved

How to throw Exceptions in JNI

Posted on 2004-08-16
9
451 Views
Last Modified: 2013-11-23
Hello all,

How to throw Exceptions in JNI??

class  TestException
{
      public native String getFileType(String magicFile,String strFile)throws Exception;
      public static void main(String[] args)
      {
            System.out.println("Hello World!");
      }
}


javah generated code

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class TestException */

#ifndef _Included_TestException
#define _Included_TestException
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     TestException
 * Method:    getFileType
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_TestException_getFileType
  (JNIEnv *, jobject, jstring, jstring);

#ifdef __cplusplus
}
#endif
#endif


JNIEXPORT jstring JNICALL Java_TestException_getFileType
  (JNIEnv *env, jobject object , jstring str1, jstring str2)
{
//some blah blah blah
 
 //now assume exception raised here. then how should c source should return exception object to JVM.
}

Thanks and Best Regards
Sudhakar
0
Comment
Question by:sudhakar_koundinya
  • 4
  • 3
  • 2
9 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 125 total points
ID: 11807568
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11807587
thanks. take ur A
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11807591
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11807597
oooooooooopss!!!
forgot to reload the question
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 35

Expert Comment

by:girionis
ID: 11807602
Thank you for accepting, glad I was of help :)
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11807962
girionis

one quick question

after throwing error if i don't return anything JVM is raising exception. Is it must to return some thing
if(strlen(getError())>0)
      {
            jclass excCls = (*env)->FindClass(env,"java/lang/Exception");
            if (excCls != 0)
            {
                  (*env)->ThrowNew(env, excCls, getError());
                  return ""; //ok ->Is this must here??
                  //return ""; //not ok
            }
      }

0
 
LVL 35

Expert Comment

by:girionis
ID: 11808008
Are you calling it from a C function that returns something? If yes then I'd expect that you need to return something anyway.
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 11808286
ok, I understand that

Thanks for nice links :-)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11808308
:)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now