Example usage for java.lang ArithmeticException printStackTrace

List of usage examples for java.lang ArithmeticException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    int[] array = new int[] { 1, 0, 2 };
    int index = 0;
    try {/* www  .  jav  a2s  .co  m*/
        System.out.println("\nFirst try block in divide() entered");
        array[index + 2] = array[index] / array[index + 1];
        System.out.println("Code at end of first try block in divide()");
    } catch (ArithmeticException e) {
        System.err.println("Arithmetic exception caught in divide()\n" + "\nMessage in exception object:\n\t"
                + e.getMessage());
        System.err.println("\nStack trace output:\n");
        e.printStackTrace();
        System.err.println("\nEnd of stack trace output\n");
    } catch (ArrayIndexOutOfBoundsException e) {
        System.err.println("Index-out-of-bounds exception caught in divide()\n"
                + "\nMessage in exception object:\n\t" + e.getMessage());
        System.err.println("\nStack trace output:\n");
        e.printStackTrace();
        System.out.println("\nEnd of stack trace output\n");
    } finally {
        System.err.println("finally clause in divide()");
    }
    System.out.println("Executing code after try block in divide()");
}

From source file:org.voltdb.regressionsuites.RegressionSuite.java

static protected void validateRowOfLongs(String messagePrefix, VoltTable vt, long[] expected) {
    int len = expected.length;
    assertTrue(vt.advanceRow());//from w w  w.  ja  v a2 s  . c  om
    for (int i = 0; i < len; i++) {
        String message = messagePrefix + "at column " + i + ", ";

        long actual = -10000000;
        // ENG-4295: hsql bug: HSQLBackend sometimes returns wrong column type.
        try {
            actual = vt.getLong(i);
        } catch (IllegalArgumentException ex) {
            try {
                actual = (long) vt.getDouble(i);
            } catch (IllegalArgumentException newEx) {
                try {
                    actual = vt.getTimestampAsLong(i);
                } catch (IllegalArgumentException exTm) {
                    try {
                        actual = vt.getDecimalAsBigDecimal(i).longValueExact();
                    } catch (IllegalArgumentException newerEx) {
                        newerEx.printStackTrace();
                        fail(message);
                    }
                } catch (ArithmeticException newestEx) {
                    newestEx.printStackTrace();
                    fail(message);
                }
            }
        }

        // Long.MIN_VALUE is like a NULL
        if (expected[i] != Long.MIN_VALUE) {
            assertEquals(message, expected[i], actual);
        } else {
            VoltType type = vt.getColumnType(i);
            assertEquals(message + "expected null: ", Long.parseLong(type.getNullValue().toString()), actual);
        }
    }
}