Solved

How to throw Exceptions in JNI

Posted on 2004-08-16
9
470 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:expertmb
ID: 11807597
oooooooooopss!!!
forgot to reload the question
0
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 65
MySQL  on Tomcat 8 68
how to debug htl and js pages 8 38
java imports not found 4 24
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

839 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