Example usage for java.lang ArithmeticException ArithmeticException

List of usage examples for java.lang ArithmeticException ArithmeticException

Introduction

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

Prototype

public ArithmeticException() 

Source Link

Document

Constructs an ArithmeticException with no detail message.

Usage

From source file:MainClass.java

public void run() {
    throw new ArithmeticException();
}

From source file:org.eurekastreams.commons.server.ExceptionSanitizerTest.java

/**
 * Tests how exceptions are returned to client.
 *//* ww w  .  j  a  v  a2 s.c o  m*/
@Test
public void testExecutionExceptionNested() {
    Exception exIn = new ExecutionException(new ArithmeticException());
    Exception exOut = coreForbidNestingExceptionTest(exIn);
    assertTrue(exOut instanceof ExecutionException);
    assertEquals(exIn.getMessage(), exOut.getMessage());
}

From source file:org.eurekastreams.commons.server.ExceptionSanitizerTest.java

/**
 * Tests how exceptions are returned to client.
 *///from   www.  j  av a  2  s . co m
@Test
public void testGeneralExceptionNested() {
    Exception exIn = new GeneralException(new ArithmeticException());
    Exception exOut = coreForbidNestingExceptionTest(exIn);
    assertTrue(exOut instanceof GeneralException);
    assertEquals(exIn.getMessage(), exOut.getMessage());
}

From source file:org.eurekastreams.commons.server.ExceptionSanitizerTest.java

/**
 * Tests how exceptions are returned to client.
 *//*ww  w.  java 2s.  c  o  m*/
@Test
public void testAuthorizationExceptionNested() {
    Exception exIn = new AuthorizationException(new ArithmeticException());
    Exception exOut = coreForbidNestingExceptionTest(exIn);
    assertTrue(exOut instanceof AuthorizationException);
    assertEquals(exIn.getMessage(), exOut.getMessage());
}

From source file:org.apache.struts.webapp.example2.LogonAction.java

/**
 * Look up the user, throwing an exception to simulate business logic
 * rule exceptions.//from www.  j  a  va  2s.co m
 *
 * @param database Database in which to look up the user
 * @param username Username specified on the logon form
 *
 * @exception AppException if a business logic rule is violated
 */
public User getUser(UserDatabase database, String username) throws ModuleException {

    // Force an ArithmeticException which can be handled explicitly
    if ("arithmetic".equals(username)) {
        throw new ArithmeticException();
    }

    // Force an application-specific exception which can be handled
    if ("expired".equals(username)) {
        throw new ExpiredPasswordException(username);
    }

    // Look up and return the specified user
    return ((User) database.findUser(username));

}

From source file:org.apache.openejb.math.MathRuntimeException.java

/**
 * Constructs a new <code>ArithmeticException</code> with specified formatted detail message.
 * Message formatting is delegated to {@link MessageFormat}.
 *
 * @param pattern   format specifier/* w  w w . j av  a 2  s.  c om*/
 * @param arguments format arguments
 * @return built exception
 */
public static ArithmeticException createArithmeticException(final String pattern, final Object... arguments) {
    return new ArithmeticException() {

        /** Serializable version identifier. */
        private static final long serialVersionUID = 7705628723242533939L;

        /** {@inheritDoc} */
        @Override
        public String getMessage() {
            return buildMessage(Locale.US, pattern, arguments);
        }

        /** {@inheritDoc} */
        @Override
        public String getLocalizedMessage() {
            return buildMessage(Locale.getDefault(), pattern, arguments);
        }

    };
}

From source file:ffx.utilities.BlockAverager.java

/**
 * Constructor grabs all histograms from the file and loads them into data
 * structures. TODO: figure out how to disregard histogram-bin combos that
 * aren't (currently) changing per time.
 * @param filename/* w w  w  . j  a va2 s. c o  m*/
 * @param testMode
 * @param grepCmd
 * @param psPerHisto
 * @param blockSizeStep
 * @param maxBlockSize
 * @throws java.io.IOException
 */
public BlockAverager(String filename, boolean testMode, Optional<String> grepCmd, Optional<Double> psPerHisto,
        Optional<Integer> blockSizeStep, Optional<Integer> maxBlockSize) throws IOException {
    this.TEST = testMode;
    this.psPerHisto = (psPerHisto.isPresent()) ? psPerHisto.get() : 1.0;
    this.blockSizeStep = (blockSizeStep.isPresent()) ? blockSizeStep.get() : 100;
    int linesPerHistogram = (System.getProperty("ba-lph") == null) ? 201
            : Integer.parseInt(System.getProperty("ba-lph"));

    if (TEST) {
        logger.info(" Testing Mode ");
        linesPerHistogram = 1;
    }

    File parallelInFile = new File(filename);
    int nThreads = ParallelTeam.getDefaultThreadCount();
    parallelTeam = new ParallelTeam(nThreads);
    numThreads = parallelTeam.getThreadCount();
    BlockRegion parallelBlock = new BlockRegion(parallelInFile);
    try {
        parallelTeam.execute(parallelBlock);
    } catch (Exception ex) {
        Logger.getLogger(BlockAverager.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Step 1: Find histograms and create a stream.
    Scanner scan = null;
    File outFile = null;
    if (preGrep != null) {
        File file = new File(preGrep);
        BufferedReader br = new BufferedReader(new FileReader(file));
        scan = new Scanner(br);
    } else {
        outFile = new File(filename + "-ba.tmp");
        if (outFile.exists()) {
            logger.info(format(" Previous temp file exists: %s", outFile.getName()));
            if (!outFile.canWrite()) {
                logger.severe(format("Lacked write permissions to temp file."));
            }
            System.out.print(format("   Delete it? (Y/N) "));
            Scanner kb = new Scanner(System.in);
            if (kb.nextLine().toUpperCase().startsWith("Y")) {
                outFile.delete();
                logger.info("");
            } else {
                logger.severe("Aborted by user.");
            }
        }

        // Manually accomplish a 'grep -A 201 Bins filename'.
        File inFile = new File(filename);
        BufferedReader br = new BufferedReader(new FileReader(inFile));
        scan = new Scanner(br);
        BufferedWriter bw = new BufferedWriter(new FileWriter(outFile));

        logger.info(" Parsing logfile... ");
        int numFound = 0;
        while (scan.hasNextLine()) {
            String line = scan.nextLine();
            if (TEST) { // No headers in test data.
                if (++numFound % 100 == 0) {
                    logger.info(format("    Parsed %d histograms.", numFound));
                }
                bw.write(line);
                bw.newLine();
                continue;
            }
            if (line.contains("Lambda Bins")) {
                if (++numFound % 100 == 0) {
                    logger.info(format("    Parsed %d histograms.", numFound));
                }
                bw.write(line);
                bw.newLine();
                for (int i = 0; i < linesPerHistogram; i++) {
                    if (!scan.hasNextLine() && i < linesPerHistogram) {
                        logger.warning(format("Found incomplete histogram: %d, %s", numFound, line));
                    }
                    bw.write(scan.nextLine());
                    bw.newLine();
                }
            }
        }
        bw.flush();
        scan = new Scanner(outFile);
    }

    // Parse stream into data structures.
    List<Bin> binList = new ArrayList<>();
    Histogram histo = null;
    while (scan.hasNextLine()) {
        String line = scan.nextLine();
        String[] tokens = line.split("\\s+");
        // Catch grep flotsam.
        if (tokens[0].startsWith("--")) {
            continue;
        }
        // Header line signals time for a new histogram.
        if (line.contains("Lambda Bins") || TEST) {
            if (histo != null) {
                histoList.add(histo);
            }
            histo = new Histogram(++histoIndexer);
            if (histoIndexer % 100 == 0) {
                if (psPerHisto.isPresent()) {
                    logger.info(format(" BlockAverager loaded %d histograms (simTime %.2f ps).", histoIndexer,
                            histoIndexer * this.psPerHisto));
                } else {
                    logger.info(format(" BlockAverager loaded %d histograms.", histoIndexer));
                }
            }
            if (TEST) { // No headers in test data.
                histo.bins.add(new Bin(tokens));
            }
            continue;
        }
        histo.bins.add(new Bin(tokens));
    }
    histoList.add(histo);
    Collections.sort(histoList);
    logger.info(format(""));

    numObs = histoList.size();
    this.maxBlockSize = (maxBlockSize.isPresent()) ? maxBlockSize.get() : numObs;

    // Validate
    for (int i = 1; i < histoList.size(); i++) {
        if (histoList.get(i).index != histoList.get(i - 1).index + 1
                || histoList.get(i).bins.size() != histoList.get(i - 1).bins.size()) {
            logger.warning(format("Improper indexing or bin size mismatch. i,i-1,binsi,binsi-1: %d %d %d %d",
                    histoList.get(i).index, histoList.get(i - 1).index, histoList.get(i).bins.size(),
                    histoList.get(i - 1).bins.size()));
            throw new ArithmeticException();
        }
    }

    if (outFile != null && outFile.exists()) {
        outFile.delete();
    }
    numBins = histoList.get(0).bins.size();
    this.describe();
}

From source file:ffx.numerics.MultipoleTensor.java

public void setR(double r[]) {
    switch (coordinates) {
    case QI:/*  www.  j  av  a2  s  . c o  m*/
        x = 0.0;
        y = 0.0;
        z = r(r);
        setQIRotationMatrix(r[0], r[1], r[2]);
        break;
    default:
    case GLOBAL:
        x = r[0];
        y = r[1];
        z = r[2];
        r2 = (x * x + y * y + z * z);
        if (r2 == 0.0) {
            throw new ArithmeticException();
        }
        R = sqrt(r2);
    }
}

From source file:ffx.numerics.MultipoleTensor.java

public void setR(double r[], double lambdaFunction) {
    switch (coordinates) {
    case QI:/*from w ww .j  a v a2  s  .  c o m*/
        setR_QI(r, lambdaFunction);
        break;
    case GLOBAL:
        x = r[0];
        y = r[1];
        z = r[2] + lambdaFunction;
        r2 = (x * x + y * y + z * z);
        if (r2 == 0.0) {
            throw new ArithmeticException();
        }
        R = sqrt(r2);
    }
}

From source file:ffx.numerics.MultipoleTensor.java

public void setR_QI(double r[]) {
    x = 0.0;/*from ww w. jav a2 s .  co m*/
    y = 0.0;
    r2 = r[0] * r[0] + r[1] * r[1] + r[2] * r[2];
    if (r2 == 0.0) {
        throw new ArithmeticException();
    }
    z = sqrt(r2);
    R = z;
    setQIRotationMatrix(r[0], r[1], r[2]);
}