• Post Reply Bookmark Topic Watch Topic
  • New Topic

How print NET_API_STATUS into exception message?

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a JNI app that throws an exception (via (*env)->ThrowNew) when an error occurs. The problem is that when I pass the error number (which is a NET_API_STATUS - I believe a dword but not sure) into it, it prints out some symbols (an "L", a degrees symbol and a spade) instead of the number 53 (which was the error).

I've tried everything in converting the number to a char*. I tried:
* itoa()
* wsprintf( buffer, L"%d", retVal ) //And I've tried this with %i, %d\0, etc
* the above with TEXT( "%d" )
* a long solution which uses a char[5] and % (i.e. num%10) looping through and converting each place to a num by adding 48...

Nothing works!

Any ideas?
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone? help, please...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any of these should be workable; itoa() is a nice easy solution. I'm pretty sure that it's OK to pass an automatic buffer to ThrowNew; it's just going to copy the characters into a Java string, after all.

So something as simple as

char buffer[10];
jclazz clazz = (*env)->FindClass(env, "java/lang/Exception");
(*env)->ThrowNew(env, clazz, itoa(NET_API_STATUS, buffer, 10));

doesn't work? In the above, I skipped error checking on FindClass and ThrowNew return values -- in real code you'd want to check those.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!