strerror equivalent JAVA

J

Jaskaran Singh

Hi,

Is there an equivalent of the C function:

char* strerror (int errno); (defined in string.h)

in JAVA? I need to obtain the corresponding error string for the error
code returned by a process, in my JAVA code.

Thanks,
Jaskaran
 
A

Andy Fish

the short answer is no

strerror() is used to examine return codes from c runtime library calls
which in general won't be visible to java programs. where are you getting
this error code from?
 
G

Gordon Beaton

Is there an equivalent of the C function:

char* strerror (int errno); (defined in string.h)

in JAVA? I need to obtain the corresponding error string for the
error code returned by a process, in my JAVA code.

comp.lang.java.developer is not a valid newsgroup.

Also please don't multipost. Follow-up set.


Most aplications don't return "errno" style values, which are intended
to indicate why a system call has failed. Normally they'll return one
of EXIT_SUCCESS or EXIT_FAILURE (e.g. 0 or 1).

An application may use a small number of different values to indicate
common types of failures specific to that particular application.
Consider that things like "the command line couldn't be parsed",
"source and destination are same file", and "the search term was not
found" are typical application failure modes not covered by any errno
values.

If a process is killed by a signal, a different kind of value is
received by the parent to indicate that fact.

If you really need this functionality, write a short native method to
return the string for a given errno. Or write a method to open
/usr/include/errno.h and find the corresponding string (this is
probably harder than it sounds). Or hardcode the values into your
class (but realize that the values are platform specific).

Doesn't the process display an error message indicating why it fails?
Why don't you simply read that from its stderr stream?

/gordon
 
L

Liz

Gordon Beaton said:
comp.lang.java.developer is not a valid newsgroup.

Also please don't multipost. Follow-up set.


Most aplications don't return "errno" style values, which are intended
to indicate why a system call has failed. Normally they'll return one
of EXIT_SUCCESS or EXIT_FAILURE (e.g. 0 or 1).

An application may use a small number of different values to indicate
common types of failures specific to that particular application.
Consider that things like "the command line couldn't be parsed",
"source and destination are same file", and "the search term was not
found" are typical application failure modes not covered by any errno
values.

If a process is killed by a signal, a different kind of value is
received by the parent to indicate that fact.

If you really need this functionality, write a short native method to
return the string for a given errno. Or write a method to open
/usr/include/errno.h and find the corresponding string (this is
probably harder than it sounds). Or hardcode the values into your
class (but realize that the values are platform specific).

Doesn't the process display an error message indicating why it fails?
Why don't you simply read that from its stderr stream?

It is so simple if you just copy the text from the header file and
make up a class that you invoke with a parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top