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() 

Source Link

Document

Constructs a new exception with null as its detail message.

Usage

From source file:Main.java

public static void main(String args[]) {
    System.out.println(new Exception().getStackTrace()[0].getMethodName());
}

From source file:Main.java

public static void main(String args[]) {
    Logger log = Logger.getAnonymousLogger();
    setLoggerhandler(log);//from   www . j a  v  a  2  s. co  m

    log.finest(new Exception().toString());
}

From source file:de.tbuchloh.kiskis.gui.feedback.SubmitBugTest.java

public static void main(String[] args) throws Exception {
    Desktop.getDesktop().mail();/*from  www.  j  a v a2 s .  c o  m*/
    new SubmitBug().openMail(TextMessageBox.exceptionToString(new Exception()));
}

From source file:de.tbuchloh.kiskis.gui.feedback.SubmitFeatureRequestTest.java

public static void main(String[] args) throws Exception {
    Desktop.getDesktop().mail();/*from  www.  j a v  a2s .  com*/
    new SubmitFeatureRequest().openMail(TextMessageBox.exceptionToString(new Exception()));
}

From source file:UnitTest4.java

public static void main(String args[]) {
    System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
    System.setProperty("org.slf4j.simpleLogger.showThreadName", "true");
    System.setProperty("org.slf4j.simpleLogger.levelInBrackets", "true");
    System.setProperty("org.slf4j.simpleLogger.dateTimeFormat", "yyyy-MM-dd HH:mm:ss:SSS Z");
    System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
    System.setProperty("org.slf4j.simpleLogger.showLogName", "true");

    final Logger log = LoggerFactory.getLogger(UnitTest4.class);
    UnitTest4.log = log;// www.j  av  a  2  s  . com
    System.out.println("hdfjkv \'dfdgdf\'dgdf");
    try {

        throw new Exception();
    } catch (Throwable e) {

        log.debug(e.toString());
        //log.debug(" Cause : " + e.getCause().toString());
        StackTraceElement stacka[] = e.getStackTrace();
        for (StackTraceElement stack : stacka) {
            log.debug(" StackTrace : " + stack.toString());
        }
    }

    String a[] = new String[10];
    a[0] = "hwedf";
    a[6] = "wdeeg";
    log.debug("a.toString() : {}", a.toString());

    /*
    List<Integer> list = new ArrayList<Integer>();
    for (Integer i : list) {
            
    System.out.println(i);
    }
    System.out.println("ok");
    try {
       //Test2.execute();
    } catch (Exception e) { e.printStackTrace(); }
    */
}

From source file:ReadTemp.java

/**
 * Method main/*from   ww w  . j a va 2s .  co  m*/
 *
 *
 * @param args
 *
 * @throws OneWireException
 * @throws OneWireIOException
 *
 */
public static void main(String[] args) throws OneWireIOException, OneWireException {
    boolean usedefault = false;
    DSPortAdapter access = null;
    String adapter_name = null;
    String port_name = null;

    variableNames = new HashMap();

    if ((args == null) || (args.length < 1)) {
        try {
            access = OneWireAccessProvider.getDefaultAdapter();

            if (access == null)
                throw new Exception();
        } catch (Exception e) {
            System.out.println("Couldn't get default adapter!");
            printUsageString();

            return;
        }

        usedefault = true;
    }

    if (!usedefault) {
        StringTokenizer st = new StringTokenizer(args[0], "_");

        if (st.countTokens() != 2) {
            printUsageString();

            return;
        }

        adapter_name = st.nextToken();
        port_name = st.nextToken();

        System.out.println("Adapter Name: " + adapter_name);
        System.out.println("Port Name: " + port_name);
    }

    if (access == null) {
        try {
            access = OneWireAccessProvider.getAdapter(adapter_name, port_name);
        } catch (Exception e) {
            System.out.println("That is not a valid adapter/port combination.");

            Enumeration en = OneWireAccessProvider.enumerateAllAdapters();

            while (en.hasMoreElements()) {
                DSPortAdapter temp = (DSPortAdapter) en.nextElement();

                System.out.println("Adapter: " + temp.getAdapterName());

                Enumeration f = temp.getPortNames();

                while (f.hasMoreElements()) {
                    System.out.println("   Port name : " + ((String) f.nextElement()));
                }
            }

            return;
        }
    }

    boolean scan = false;

    if (args.length > 1) {
        if (args[1].compareTo("--scan") == 0)
            scan = true;
    } else {
        populateVariableNames();
    }

    while (true) {
        access.adapterDetected();
        access.targetAllFamilies();
        access.beginExclusive(true);
        access.reset();
        access.setSearchAllDevices();

        boolean next = access.findFirstDevice();

        if (!next) {
            System.out.println("Could not find any iButtons!");

            return;
        }

        while (next) {
            OneWireContainer owc = access.getDeviceContainer();

            boolean isTempContainer = false;
            TemperatureContainer tc = null;

            try {
                tc = (TemperatureContainer) owc;
                isTempContainer = true;
            } catch (Exception e) {
                tc = null;
                isTempContainer = false; //just to reiterate
            }

            if (isTempContainer) {
                String id = owc.getAddressAsString();
                if (scan) {
                    System.out.println("= Temperature Sensor Found: " + id);
                } else {

                    double high = 0.0;
                    double low = 0.0;
                    byte[] state = tc.readDevice();

                    boolean selectable = tc.hasSelectableTemperatureResolution();

                    if (selectable)
                        try {
                            tc.setTemperatureResolution(0.0625, state);
                        } catch (Exception e) {
                            System.out.println("= Could not set resolution for " + id + ": " + e.toString());
                        }

                    try {
                        tc.writeDevice(state);
                    } catch (Exception e) {
                        System.out.println("= Could not write device state, all changes lost.");
                        System.out.println("= Exception occurred for " + id + ": " + e.toString());
                    }

                    boolean conversion = false;
                    try {
                        tc.doTemperatureConvert(state);
                        conversion = true;
                    } catch (Exception e) {
                        System.out.println("= Could not complete temperature conversion...");
                        System.out.println("= Exception occurred for " + id + ": " + e.toString());
                    }

                    if (conversion) {
                        state = tc.readDevice();

                        double temp = tc.getTemperature(state);
                        if (temp < 84) {
                            double temp_f = (9.0 / 5.0) * temp + 32;
                            setVariable(id, Double.toString(temp_f));
                        }
                        System.out.println("= Reported temperature from " + (String) variableNames.get(id) + "("
                                + id + "):" + temp);
                    }
                }
            }
            next = access.findNextDevice();
        }
        if (!scan) {
            try {
                Thread.sleep(60 * 5 * 1000);
            } catch (Exception e) {
            }
        } else {
            System.exit(0);
        }
    }
}

From source file:Main.java

public static int _LINE_() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return traceElement.getLineNumber();
}

From source file:Main.java

public static String _FUNC_() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return traceElement.getMethodName();
}

From source file:Main.java

public static String getFileLineMethod() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
            .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName())
            .append("]");
    return toStringBuffer.toString();
}

From source file:Main.java

public static String getClassName() {
    try {/* w ww  .j  ava 2s.  c  o m*/
        String fullClassName = new Exception().getStackTrace()[1].getClassName();
        return fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
    } catch (Exception ex) {
        return "UnknownClass";
    }
}