Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.ext;
 import org.jruby.Ruby;
 public class JRubyPOSIXHelper {
Helper for handling common POSIX situations where a negative return value from a function call indicates an error, and errno must be consulted to determine how exactly the function failed.

runtime Ruby runtime
result return value of a POSIX call
    public static void checkErrno(Ruby runtimeint result) {
        if (result < 0) {
        // FIXME: The error message is a bit off.
        // e.g., No such process - No such process (Errno::ESRCH)
        // Note the repetition of 'No such process'.
            Errno errno = Errno.valueOf(runtime.getPosix().errno());
            String name =;
            String msg  = errno.toString();
            RubyClass errnoClass = runtime.getErrno().getClass(name);
            if (errnoClass != null) {
                throw new RaiseException(runtimeerrnoClassmsgtrue);
New to GrepCode? Check out our FAQ X