Example usage for java.lang OutOfMemoryError getStackTrace

List of usage examples for java.lang OutOfMemoryError getStackTrace

Introduction

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

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:controllers.CNAController.java

public static void inputTable(String table, String notEffects) {
    CNAList notEffectsList;/*from   ww w  . j  a  v a  2s  .  c  o  m*/
    if (notEffects.length() == 0) {
        notEffectsList = null;
    } else {
        notEffects = notEffects.replaceAll(" ", "");
        notEffectsList = new CNAList(",", notEffects);
    }

    CNATable cnatable = new CNATable("\r\n", ",", table);

    if (cnatable.get(0).size() >= NUMFACTORS) {
        flash.error("Only up to " + NUMFACTORS + " factors allowed.");
        params.flash();
        setup();
    } else if (cnatable.get(0).size() < 3) {
        flash.error(
                "Violation of Minimal Diversity pre-condition: Every MT must have at least two bundles, alternate factors, or a bundle and a alternate factor.");
        params.flash();
        setup();
    }
    try {
        ArrayList<String> graphsView = new ArrayList<String>();
        timer = new Timer();
        CNAlgorithm cnaAlgorithm = new CNAlgorithm(cnatable, notEffectsList);
        for (MinimalTheorySet set : cnaAlgorithm.getSets()) {
            Graph graph = new Graph(set);
            Renderer renderer = new Renderer();
            renderer.setShowEdgeLabels(showBundleNumRenderer);
            renderer.config(graph);
            graphsView.add(renderer.getImageSource());
            graphsView.add(set.toString());
        }

        String elapsedTime = timer.timeElapsed() + " ms";
        boolean specialcase = false;
        render(elapsedTime, graphsView, specialcase, notEffects);
    } catch (OutOfMemoryError e) {
        try {
            ArrayList<String> graphsView = new ArrayList<String>();
            timer = new Timer();
            CNAlgorithm cnaAlgorithm = new CNAlgorithm(cnatable, notEffectsList);

            ArrayList<MinimalTheory> theories = cnaAlgorithm.getAllTheories();
            for (MinimalTheory theory : theories) {
                graphsView.add(theory.toString());
            }
            if (graphsView.size() < 1) {
                flash.error("It was not possible to calculate a graph.");
                params.flash();
                setup();
            }

            String elapsedTime = timer.timeElapsed() + " ms";
            boolean specialcase = true;
            render(elapsedTime, graphsView, specialcase);
        } catch (CNAException e1) {
            flash.error(e1.toString());
            params.flash();
            setup();
        } catch (InterruptedException e2) {
            try {
                SimpleEmail email = new SimpleEmail();
                email.setFrom(MAILFrom);
                email.addTo(MAILTo);
                email.setSubject("Error: InterruptedException");
                String msg = e.getStackTrace().toString();
                email.setMsg("CNA Input Table\n" + msg);
                Mail.send(email);
            } catch (EmailException e1) {
                e1.printStackTrace();
            }
            flash.error("Something went very wrong! Please try again or contact us.");
            params.flash();
            setup();
        } catch (ExecutionException e3) {
            try {
                SimpleEmail email = new SimpleEmail();
                email.setFrom(MAILFrom);
                email.addTo(MAILTo);
                email.setSubject("Error: ExecutionException");
                String msg = e.getStackTrace().toString();
                email.setMsg("CNA Input Table\n" + msg);
            } catch (EmailException e1) {
                e1.printStackTrace();
            }
        }
    } catch (CNAException e) {
        flash.error(e.toString());
        params.flash();
        setup();
    } catch (ArrayIndexOutOfBoundsException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: IndexOutOfBoundsException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went wrong. Please try again or contact us.");
        params.flash();
        setup();
    } catch (IndexOutOfBoundsException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: IndexOutOfBoundsException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went wrong. Please try again or contact us.");
        params.flash();
        setup();
    } catch (IllegalArgumentException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: IllegalArgumentException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went wrong. Please try again or contact us.");
        params.flash();
        setup();
    } catch (InterruptedException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: InterruptedException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went very wrong! Please try again or contact us.");
        params.flash();
        setup();
    } catch (ExecutionException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: ExecutionException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:controllers.CNAController.java

public static void calcCNAGraph(String generatedGraphSource, String generatedGraphString, String coincTable) {
    try {/* w  ww  .j a  v a  2 s.c o m*/
        timer = new Timer();
        MTSetToTable parser = new MTSetToTable(theories);
        CNATable table = parser.getCoincTable();
        CNAlgorithm cnaAlgorithm = new CNAlgorithm(table);
        ArrayList<String> graphsView = new ArrayList<String>();

        for (MinimalTheorySet set : cnaAlgorithm.getSets()) {
            Graph graph = new Graph(set);
            Renderer renderer = new Renderer();
            renderer.setShowEdgeLabels(showBundleNumRenderer);
            renderer.config(graph);
            graphsView.add(renderer.getImageSource());
            graphsView.add(set.toString());
        }

        String elapsedTime = timer.timeElapsed() + " ms";
        boolean specialcase = false;
        render(elapsedTime, graphsView, generatedGraphSource, generatedGraphString, coincTable, specialcase);
    } catch (OutOfMemoryError e) {
        try {
            ArrayList<String> graphsView = new ArrayList<String>();
            timer = new Timer();
            MTSetToTable parser = new MTSetToTable(theories);
            CNATable table = parser.getCoincTable();
            CNAlgorithm cnaAlgorithm = new CNAlgorithm(table);

            ArrayList<MinimalTheory> theories = cnaAlgorithm.getAllTheories();
            for (MinimalTheory theory : theories) {
                graphsView.add(theory.toString());
            }
            if (graphsView.size() < 1) {
                flash.error("It was not possible to calculate a graph.");
                params.flash();
                setup();
            }

            String elapsedTime = timer.timeElapsed() + " ms";
            boolean specialcase = true;

            render(elapsedTime, graphsView, generatedGraphSource, generatedGraphString, coincTable,
                    specialcase);
        } catch (CNAException e1) {
            flash.error(e1.toString());
            params.flash();
            setup();
        } catch (InterruptedException e2) {
            try {
                SimpleEmail email = new SimpleEmail();
                email.setFrom(MAILFrom);
                email.addTo(MAILTo);
                email.setSubject("Error: InterruptedException");
                String msg = e.getStackTrace().toString();
                email.setMsg("CNA Input Table\n" + msg);
                Mail.send(email);
            } catch (EmailException e1) {
                e1.printStackTrace();
            }
            flash.error("Something went very wrong! Please try again or contact us.");
            params.flash();
            setup();
        } catch (ExecutionException e3) {
            try {
                SimpleEmail email = new SimpleEmail();
                email.setFrom(MAILFrom);
                email.addTo(MAILTo);
                email.setSubject("Error: ExecutionException");
                String msg = e.getStackTrace().toString();
                email.setMsg("CNA Input Table\n" + msg);
                Mail.send(email);
            } catch (EmailException e1) {
                e1.printStackTrace();
            }
        }
    } catch (CNAException e) {
        flash.error(e.toString());
        params.flash();
        setup();
    } catch (InterruptedException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: InterruptedException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
            Mail.send(email);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
        flash.error("Something went very wrong! Please try again or contact us.");
        params.flash();
        setup();
    } catch (ExecutionException e) {
        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(MAILFrom);
            email.addTo(MAILTo);
            email.setSubject("Error: ExecutionException");
            String msg = e.getStackTrace().toString();
            email.setMsg("CNA Input Table\n" + msg);
        } catch (EmailException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:pyromaniac.AcaciaMain.java

/**
 * Run from command line./*w  ww  .  j av  a  2  s.  c  om*/
 *
 * @param settings the run time settings
 * @throws Exception the exception
 */
private void runFromCommandLine(HashMap<String, String> settings) throws Exception {
    this.checkSettings(settings);

    boolean errorOccurred = false;

    AcaciaLogger logger = new AcaciaLogger();
    try {
        AcaciaEngine engine = AcaciaEngine.getEngine();

        //System.out.println("Initialising the log files");

        //TODO: should not be here, but in runAcacia. Why is it here (and is it something to do with the GUI?)
        //engine.initLogFiles(settings, logger, false, null);

        LinkedList<MIDPrimerCombo> validTags = null;

        if (settings.get(AcaciaConstants.OPT_MID).equals(AcaciaConstants.OPT_LOAD_MIDS)) {
            validTags = engine.loadMIDS(settings.get(AcaciaConstants.OPT_MID_FILE), logger);
        } else {
            validTags = new LinkedList<MIDPrimerCombo>();
            validTags.add(AcaciaConstants.NO_MID_GROUP);
        }

        engine.runAcacia(settings, validTags, logger, null, AcaciaEngine.getVersion(), false);

    } catch (OutOfMemoryError error) {
        errorOccurred = true;
        logger.writeLog(error.getMessage(), AcaciaLogger.LOG_ERROR);

        StackTraceElement[] trace = error.getStackTrace();

        for (int i = 0; i < trace.length; i++) {
            logger.writeLog(trace[i].toString(), AcaciaLogger.LOG_ERROR);
        }
    } catch (Exception e) {
        errorOccurred = true;
        System.out.println(e.getMessage());
        logger.writeLog(e.getMessage(), AcaciaLogger.LOG_ERROR);

        StackTraceElement[] trace = e.getStackTrace();

        for (int i = 0; i < trace.length; i++) {
            logger.writeLog(trace[i].toString(), AcaciaLogger.LOG_ERROR);
        }
    } finally {
        try {
            logger.closeLogger();
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (errorOccurred) {
            System.exit(1);
        } else {
            System.exit(0);
        }
    }
}