Example usage for java.lang Error Error

List of usage examples for java.lang Error Error

Introduction

In this page you can find the example usage for java.lang Error Error.

Prototype

public Error(String message, Throwable cause) 

Source Link

Document

Constructs a new error with the specified detail message and cause.

Usage

From source file:mx.unam.fesa.mss.MSSMain.java

/**
 * @param args/*from   w  w w  .java2s. co m*/
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    //
    // managing command line options using commons-cli
    //

    Options options = new Options();

    // help option
    //
    options.addOption(
            OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP));

    // port option
    //
    options.addOption(OptionBuilder.withDescription("The port in which the MineSweeperServer will listen to.")
            .hasArg().withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT));

    // parsing options
    //
    int port = DEFAULT_PORT;
    try {
        // using GNU standard
        //
        CommandLine line = new GnuParser().parse(options, args);

        if (line.hasOption(OPT_HELP)) {
            new HelpFormatter().printHelp("mss [options]", options);
            return;
        }

        if (line.hasOption(OPT_PORT)) {
            try {
                port = (Integer) line.getOptionObject(OPT_PORT);
            } catch (Exception e) {
            }
        }
    } catch (ParseException e) {
        System.err.println("Could not parse command line options correctly: " + e.getMessage());
        return;
    }

    //
    // configuring logging services
    //

    try {
        LogManager.getLogManager()
                .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE));
    } catch (Exception e) {
        throw new Error("Could not load logging properties file", e);
    }

    //
    // setting up UDP server
    //      

    try {
        new MSServer(port);
    } catch (Exception e) {
        LoggerFactory.getLogger(MSSMain.class).error("Could not execute MineSweeper server: ", e);
    }
}

From source file:mx.unam.fesa.isoo.msp.MSPMain.java

/**
 * @param args//from www. ja  v a  2 s. c om
 * @throws Exception
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {

    //
    // creating options
    //

    Options options = new Options();

    // help option
    //
    options.addOption(
            OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP));

    // server option
    //
    options.addOption(OptionBuilder.withDescription("The server this MineSweeperPlayer will connect to.")
            .hasArg().withArgName("SERVER").withLongOpt("server").create(OPT_SERVER));

    // port option
    //
    options.addOption(OptionBuilder.withDescription("The port this MineSweeperPlayer will connect to.").hasArg()
            .withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT));

    // parsing options
    //
    String hostname = DEFAULT_SERVER;
    int port = DEFAULT_PORT;
    try {
        // using GNU standard
        //
        CommandLine line = new GnuParser().parse(options, args);

        if (line.hasOption(OPT_HELP)) {
            new HelpFormatter().printHelp("msc [options]", options);
            return;
        }

        if (line.hasOption(OPT_PORT)) {
            try {
                port = (Integer) line.getOptionObject(OPT_PORT);
            } catch (Exception e) {
            }
        }

        if (line.hasOption(OPT_SERVER)) {
            hostname = line.getOptionValue(OPT_PORT);
        }
    } catch (ParseException e) {
        System.err.println("Could not parse command line options correctly: " + e.getMessage());
        return;
    }

    //
    // configuring logging services
    //

    try {
        LogManager.getLogManager()
                .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE));
    } catch (Exception e) {
        throw new Error("Could not load logging properties file.", e);
    }

    //
    // setting up Mine Sweeper client
    //

    try {
        new MSClient(hostname, port);
    } catch (Exception e) {
        System.err.println("Could not execute MineSweeper client: " + e.getMessage());
    }
}

From source file:Main.java

private static JAXBContext initContext() {
    try {//from  www  .ja  va  2s  . c  om
        return JAXBContext.newInstance("com.tda.sitefilm.allocine.jaxb");
    } catch (JAXBException error) {
        throw new Error("XMLAllocineAPIHelper: Got error during initialization", error);
    }
}

From source file:com.github.ffremont.microservices.springboot.manager.security.DicoError.java

public Error findError(int code) {
    if (this.errors.containsKey(code)) {
        return new Error(code, this.errors.get(code));
    } else {//w  w  w. j  a v  a  2s.c om
        return new Error(DEFAULT_ERROR_CODE, this.errors.get(DEFAULT_ERROR_CODE));
    }
}

From source file:com.baidu.rigel.biplatform.parser.util.PropertiesUtil.java

/** 
 * toString/*from   w  ww  . j a va2 s. c om*/
 * @param props
 * @param comment
 * @param encoding
 * @return
 * @throws UnsupportedEncodingException
 */
public static String toString(Properties props, String comment, String encoding)
        throws UnsupportedEncodingException {
    ByteArrayOutputStream baos = null;
    try {
        baos = new ByteArrayOutputStream();
        props.store(baos, comment);
        baos.flush();
        return new String(baos.toByteArray(), encoding);
    } catch (UnsupportedEncodingException e) {
        throw e;
    } catch (IOException e) {
        throw new Error("An IOException while working with byte array streams?!", e);
    } finally {
        IOUtils.closeQuietly(baos);
    }
}

From source file:net.hillsdon.fij.text.Escape.java

/**
 * Generate a correctly encoded URI string from the given components.
 * //from   w w  w .j  a  v  a  2 s  . c  o  m
 * @param path The unencoded path. Will be encoded according to RFC3986.
 * @param query The unencoded query. May be null. Will be x-www-form-urlencoded.
 * @param fragment The unencoded fragment. May be null. Will be encoded according to RFC3986.
 * @param extraPath The <strong>encoded</strong> extra part to append to the path.
 * @return
 */
public static String constructEncodedURI(final String path, final String query, final String fragment,
        final String extraPath) {
    try {
        StringBuilder sb = new StringBuilder();
        sb.append(URIUtil.encodeWithinPath(path, "UTF-8"));
        if (extraPath != null) {
            sb.append(extraPath);
        }
        if (query != null) {
            sb.append("?");
            sb.append(URIUtil.encodeQuery(query, "UTF-8"));
        }
        if (fragment != null) {
            sb.append("#");
            sb.append(URIUtil.encodeWithinPath(fragment, "UTF-8"));
        }
        return sb.toString();
    } catch (URIException ex) {
        throw new Error("Java supports UTF-8!", ex);
    }
}

From source file:Main.java

public static Object clone(final Object obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }/*from   w  w  w.j a va 2 s.c  o m*/
    if (obj instanceof Cloneable) {
        Class<?> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            return m.invoke(obj, (Object[]) null);
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:dk.statsbiblioteket.doms.surveillance.surveyor.SurveyorServletUtils.java

/**
 * Handle actions given a servlet request on a surveyor.
 * Will handle requests to mark a log message as handled, and requests
 * never to show a given message again./*from ww  w . j av  a 2 s  .c  o  m*/
 * @param request The request containing the parameters.
 * @param surveyor The surveyor to call the actions on.
 */
public static void handlePostedParameters(HttpServletRequest request, Surveyor surveyor) {
    log.trace("Enter handlePostedParameters()");
    String applicationName;

    try {
        request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e) {
        //UTF-8 must be supported as per spec.
        throw new Error("UTF-8 unsupported by JVM", e);
    }

    applicationName = request.getParameter("applicationname");
    if (applicationName != null) {
        Map<String, String[]> parameters = request.getParameterMap();
        for (String key : parameters.keySet()) {
            if (key.startsWith("handle:") && Arrays.equals(new String[] { "Handled" }, parameters.get(key))) {
                surveyor.markHandled(applicationName, key.substring("handle:".length()));
            }
        }
        if (request.getParameter("notagain") != null) {
            surveyor.notAgain(applicationName, request.getParameter("notagain"));
        }
    }
}

From source file:Main.java

/**
 * @since 4.3/*from w  w w.ja  v  a2  s  .c  o  m*/
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:Main.java

/**
 * @since 4.3/* w ww .j av a2 s  .  c o  m*/
 */
public static <T> T cloneObject(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }
    if (obj instanceof Cloneable) {
        final Class<?> clazz = obj.getClass();
        final Method m;
        try {
            m = clazz.getMethod("clone", (Class<?>[]) null);
        } catch (final NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            @SuppressWarnings("unchecked")
            // OK because clone() preserves the class
            final T result = (T) m.invoke(obj, (Object[]) null);
            return result;
        } catch (final InvocationTargetException ex) {
            final Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}