Example usage for java.lang Exception Exception

List of usage examples for java.lang Exception Exception

Introduction

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

Prototype

public Exception(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static void main(String[] argv) {
    Throwable t = new Exception("from java2s.com");

    System.out.println(t.getSuppressed());

}

From source file:Main.java

public static void main(String[] argv) {
    Throwable t = new Exception("from java2s.com");

    t.fillInStackTrace();

}

From source file:Main.java

public static void main(String args[]) {
    try {/*from   www.  j a  v  a 2 s. c  om*/
        throw new Exception("for no reason!");
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        System.out.println(sw.toString().toUpperCase());
    }
}

From source file:Main.java

public static void main(String[] argv) throws FileNotFoundException {
    Throwable t = new Exception("from java2s.com");

    t.setStackTrace(new Exception("java2s.com").getStackTrace());

}

From source file:Main.java

public static void main(String[] argv) throws FileNotFoundException {
    Throwable t = new Exception("from java2s.com");

    t.printStackTrace(new PrintWriter("file.name"));

}

From source file:base64test.Base64Test.java

/**
 * @param args the command line arguments
 *///from  w  w  w .  java 2  s .co  m
public static void main(String[] args) {
    try {
        if (!Base64.isBase64(args[0])) {
            throw new Exception("Arg 1 is not a Base64 string!");
        } else {
            String decodedBase64String = new String(Base64.decodeBase64(args[0]));
            File tempFile = File.createTempFile("base64Test", ".tmp");
            tempFile.deleteOnExit();
            FileWriter fw = new FileWriter(tempFile, false);
            PrintWriter pw = new PrintWriter(fw);
            pw.write(decodedBase64String);
            pw.close();
            String fileType = getFileType(tempFile.toPath());
            System.out.println(fileType);
            System.in.read();
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

From source file:StdErrOutWindows.java

public static void main(String[] args) {
    new StdErrOutWindows();
    System.out.println("test to out");
    try {//  w ww.  j a va 2 s .  c  o  m
        throw new Exception("Test exception");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:LoggingTrial.java

public static void main(String[] args) {
    Log log = LogFactory.getLog(LoggingTrial.class);
    System.out.println("The Log being used >>> " + log);

    Exception e = new Exception("A DUMMY EXCEPTION");
    if (log.isTraceEnabled()) {
        log.trace("TRACE TEST");
        log.trace("TRACE TEST", e);
    }/*from w w  w .j  a va2 s.c  o  m*/
    if (log.isDebugEnabled()) {
        log.debug("DEBUG TEST");
        log.debug("DEBUG TEST", e);
    }

    if (log.isInfoEnabled()) {
        log.info("INFO TEST");
        log.info("INFO TEST", e);
    }
    if (log.isWarnEnabled()) {
        log.warn("WARN TEST");
        log.warn("WARN TEST", e);
    }

    if (log.isErrorEnabled()) {
        log.error("ERROR TEST");
        log.error("ERROR TEST", e);
    }

    if (log.isFatalEnabled()) {
        log.fatal("FATAL TEST");
        log.fatal("FATAL TEST", e);
    }
}

From source file:com.ipcglobal.awscdh.config.ManageCluster.java

/**
 * The main method.//w  ww .  ja va  2s .  c  o  m
 *
 * @param args the arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {
    try {
        long before = System.currentTimeMillis();
        LogTool.initConsole();
        if (args.length <= 1)
            throw new Exception(
                    "Action and Properties file name are required parameter - format: start|stop example.properties");
        String action = args[0];
        log.info("Begin: action=" + action);
        Properties properties = new Properties();
        properties.load(new FileInputStream(args[1]));
        ManageEc2 manageEc2 = new ManageEc2(properties);
        ManageCdh manageCdh = new ManageCdh(properties);

        if ("start".equals(action)) {
            manageEc2.start();
            manageCdh.start();
        } else if ("stop".equals(action)) {
            manageCdh.stop();
            manageEc2.stop();
        } else
            throw new Exception("Invalid action: " + action + ", must be start or stop");

        log.info("Complete: action=" + action + ", elapsed "
                + Utils.convertMSecsToHMmSs(System.currentTimeMillis() - before));

    } catch (Exception e) {
        log.error(e);
        e.printStackTrace();
    }
}

From source file:edu.msu.cme.rdp.readseq.ToFasta.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption("m", "mask", true, "Mask sequence name indicating columns to drop");
    String maskSeqid = null;//from   www  . j av  a2 s .c om

    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("mask")) {
            maskSeqid = line.getOptionValue("mask");
        }

        args = line.getArgs();
        if (args.length == 0) {
            throw new Exception("");
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp("USAGE: to-fasta <input-file>", options);
        System.err.println("ERROR: " + e.getMessage());
        System.exit(1);
        return;
    }

    SeqReader reader = null;

    FastaWriter out = new FastaWriter(System.out);
    Sequence seq;
    int totalSeqs = 0;
    long totalTime = System.currentTimeMillis();

    for (String fname : args) {
        if (fname.equals("-")) {
            reader = new SequenceReader(System.in);
        } else {
            File seqFile = new File(fname);

            if (maskSeqid == null) {
                reader = new SequenceReader(seqFile);
            } else {
                reader = new IndexedSeqReader(seqFile, maskSeqid);
            }
        }

        long startTime = System.currentTimeMillis();
        int thisFileTotalSeqs = 0;
        while ((seq = reader.readNextSequence()) != null) {
            out.writeSeq(seq.getSeqName().replace(" ", "_"), seq.getDesc(), seq.getSeqString());
            thisFileTotalSeqs++;
        }
        totalSeqs += thisFileTotalSeqs;
        System.err.println("Converted " + thisFileTotalSeqs + " (total sequences: " + totalSeqs
                + ") sequences from " + fname + " (" + reader.getFormat() + ") to fasta in "
                + (System.currentTimeMillis() - startTime) / 1000 + " s");
    }
    System.err.println("Converted " + totalSeqs + " to fasta in "
            + (System.currentTimeMillis() - totalTime) / 1000 + " s");

    out.close();
}