Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.github.r351574nc3.amex.assignment2.App.java

/**
 * Loads the MPG data file from UCI//from   ww w .  jav a 2s.  c om
 *
 * @param {@link String} intances of path of the dataset
 * @return {@link Instances} instance containing all records of the dataset.
 */
public Instances load(final String mpgFile) throws Exception {
    try {
        final Instances retval = DataSource.read(mpgFile);
        retval.setClassIndex(0);
        retval.deleteStringAttributes();
        return retval;
    } catch (Exception e) {
        error("%s:%s", UNABLE_TO_LOAD_DATA_MESSAGE, e.getClass().getSimpleName());
        e.printStackTrace();
    }

    return null;

}

From source file:com.neuron.trafikanten.dataProviders.trafikanten.TrafikantenSearch.java

@Override
public void run() {
    try {/* w  w  w.  j  a v  a 2  s.c o m*/
        String urlString;

        if (query != null) {
            /*
             * Setup URL for a normal station search query.
             */
            urlString = Trafikanten.getApiUrl() + "/ReisRest/Place/FindMatches/"
                    + HelperFunctions.properEncode(query);
        } else {
            /*
             * Setup URL for coordinate search.
             */
            final LatLng latLong = new LatLng(latitude, longitude);
            final UTMRef utmRef = latLong.toUTMRef();
            urlString = Trafikanten.getApiUrl() + "/ReisRest/Stop/GetClosestStopsByCoordinates/?coordinates=(X="
                    + (int) utmRef.getEasting() + ",Y=" + (int) utmRef.getNorthing() + ")&proposals=10";
        }
        Log.i(TAG, "Searching with url " + urlString);
        final InputStream stream = HelperFunctions.executeHttpRequest(context, new HttpGet(urlString),
                false).stream;

        /*
         * Parse json
         */
        final JSONArray jsonArray = new JSONArray(HelperFunctions.InputStreamToString(stream));
        final int arraySize = jsonArray.length();
        for (int i = 0; i < arraySize; i++) {
            final JSONObject json = jsonArray.getJSONObject(i);
            StationData station = new StationData();

            // We parse realtimestop first for performance reason.
            station.realtimeStop = json.has("RealTimeStop") && json.getBoolean("RealTimeStop");
            if (isRealtimeStopFiltered && !station.realtimeStop) {
                continue;
            }

            station.stationId = json.getInt("ID");
            station.type = json.getInt("Type");
            station.stopName = json.getString("Name");
            searchForAddress(station);

            final String district = json.getString("District");
            if (district.length() > 0) {
                if (station.extra == null) {
                    station.extra = district;
                } else {
                    station.extra = station.extra + ", " + district;
                }
            }

            if (json.has("WalkingDistance")) {
                station.walkingDistance = json.getInt("WalkingDistance");
            }
            station.utmCoords[0] = json.getInt("X");
            station.utmCoords[1] = json.getInt("Y");

            ThreadHandlePostData(station);
        }
    } catch (Exception e) {
        if (e.getClass() == InterruptedException.class) {
            ThreadHandlePostExecute(null);
            return;
        }
        ThreadHandlePostExecute(e);
        return;
    }
    ThreadHandlePostExecute(null);
}

From source file:com.basetechnology.s0.agentserver.script.runtime.ExceptionInfo.java

public ExceptionInfo(Exception exception, String type, String message, long time, String scriptName) {
    this.exception = exception;
    this.type = type != null ? type : exception != null ? exception.getClass().getName() : null;
    this.message = message != null ? message : exception != null ? exception.getMessage() : null;
    this.time = time > 0 ? time : System.currentTimeMillis();
    this.scriptName = scriptName;
}

From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java

/**
 * Manipula excees para status HTTP {@code 500}
 *
 * @param ex// w ww.  jav a2s  .c o  m
 *            {@link Exception}
 * @return resposta ao cliente
 */
@ResponseBody
@ExceptionHandler({ ConversionNotSupportedException.class, HttpMessageNotWritableException.class })
public Response<E> processInternalServerErrors(final Exception ex) {
    this.logger.info("handle" + ex.getClass().getName() + " - Catching: " + ex.getClass().getSimpleName(), ex);
    return new ResponseBuilder<E>().success(false).message(ex.getMessage())
            .status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}

From source file:org.sakaiproject.shortenedurl.impl.BitlyUrlService.java

/**
 * Makes a GET request to the given address. Any query string should be appended already.
 * @param address   the fully qualified URL to make the request to
 * @return/*from  w ww . jav  a 2 s . c o  m*/
 */
private String doGet(String address) {
    try {

        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(address);
        HttpResponse response = httpclient.execute(httpget);

        //check reponse code
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != 200) {
            log.error("Error shortening URL. Status: " + status.getStatusCode() + ", reason: "
                    + status.getReasonPhrase());
            return null;
        }

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            return EntityUtils.toString(entity);
        }

    } catch (Exception e) {
        log.error(e.getClass() + ":" + e.getMessage());
    }
    return null;
}

From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928AbstractVersionTest.java

/**
 * DOCUMENT ME!/*from   www. j  a v  a  2s  .  co m*/
*/
public void testNoMigrationExecution() {
    try {
        manager.find(Freezed.class, null, null);
        fail("Should throw a exception because no migration was made!");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), FloggyException.class);
    }
}

From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928AbstractVersionTest.java

/**
 * DOCUMENT ME!// ww w .j  a v a  2 s .  c o m
*/
public void testThrowExceptionWhenMigratingFromPreviousVersion() {
    try {
        MigrationManager.getInstance().start(FR2422928.class, null);
        fail("Should throw a exception because the property MigrationManager.MIGRATE_FROM_PREVIOUS_FLOGGY_VERSION is not set to true!");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), FloggyException.class);
    }
}

From source file:br.com.modoagil.asr.rest.support.RESTErrorHandler.java

/**
 * Manipula excees para status HTTP {@code 400}
 *
 * @param ex/*from ww w  .  jav  a2 s .  com*/
 *            {@link Exception}
 * @return resposta ao cliente
 */
@ResponseBody
@ExceptionHandler({ BindException.class, HttpMessageNotReadableException.class,
        MissingServletRequestParameterException.class, MissingServletRequestPartException.class,
        TypeMismatchException.class })
public Response<E> processBadRequestExceptions(final Exception ex) {
    this.logger.info("handle" + ex.getClass().getName() + " - Catching: " + ex.getClass().getSimpleName(), ex);
    return new ResponseBuilder<E>().success(false).message(ex.getMessage()).status(HttpStatus.BAD_REQUEST)
            .build();
}

From source file:org.opendaylight.sfc.sbrest.json.SfgExporterTest.java

@Test
// put wrong argument, illegal argument exception is expected
public void testExportJsonException() throws Exception {
    ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder = new ServiceFunctionForwarderBuilder();
    SfgExporter sfgExporter = new SfgExporter();

    try {//from w  ww.j av  a2s . c o m
        sfgExporter.exportJson(serviceFunctionForwarderBuilder.build());
    } catch (Exception exception) {
        assertEquals("Must be true", exception.getClass(), IllegalArgumentException.class);
    }

    try {
        sfgExporter.exportJsonNameOnly(serviceFunctionForwarderBuilder.build());
    } catch (Exception exception) {
        assertEquals("Must be true", exception.getClass(), IllegalArgumentException.class);
    }
}

From source file:WebCategorizer.java

public void getWebCategories(HashSet<String> urlSet, HashMap<String, String> websiteCategoryMap,
        MongoCollection<org.bson.Document> websiteCategoryCollection) {
    try {//from   www.j a v a  2  s. c om
        File file = new File(categoriesFile);
        JSONObject webCatList = new JSONObject();
        if (file.exists() && file.length() != 0) {
            webCatList = loadCategories();
        } else {
            webCatList = fetchCategories();
        }
        for (String url : urlSet) {
            if (websiteCategoryMap.containsKey(url))
                continue;
            org.bson.Document urlDoc = websiteCategoryCollection.find(eq("URLDomain", url)).first();
            if (urlDoc == null) {
                String host = "";
                String port = "";
                if (url.indexOf(':') > -1) {
                    String[] urlAddr = url.split(":");
                    host = urlAddr[0];
                    port = urlAddr[1];
                } else {
                    host = url;
                    port = "80";
                }
                StringBuilder remoteUrl = new StringBuilder("http://sp.cwfservice.net/1/R/");
                remoteUrl.append(k9License);
                remoteUrl.append("/K9-00006/0/GET/HTTP/");
                remoteUrl.append(host);
                remoteUrl.append("/");
                remoteUrl.append(port);
                remoteUrl.append("///");

                //Fetch Key for URL
                URL obj = new URL(remoteUrl.toString());
                URLConnection connection = obj.openConnection();

                Document doc = parseXML(connection.getInputStream());

                NodeList descNodes = doc.getElementsByTagName("DomC");
                if (descNodes.getLength() != 0) {
                    String cat = (String) webCatList
                            .get(breakString(descNodes.item(0).getTextContent().toLowerCase()));
                    websiteCategoryMap.put(url, cat);
                    websiteCategoryCollection.insertOne(new org.bson.Document("URLId", url.hashCode())
                            .append("URLDomain", url.toString()).append("URLCategory", cat));
                } else {
                    descNodes = doc.getElementsByTagName("DirC");
                    String cat = (String) webCatList
                            .get(breakString(descNodes.item(0).getTextContent().toLowerCase()));
                    websiteCategoryMap.put(url, cat);
                    websiteCategoryCollection.insertOne(new org.bson.Document("URLId", url.hashCode())
                            .append("URLDomain", url.toString()).append("URLCategory", cat));
                }
            } else {
                websiteCategoryMap.put(url, new JSONObject(urlDoc.toJson()).get("URLCategory").toString());
            }
        }
    } catch (Exception ex) {
        System.out.println(ex.getClass().getName());
        System.out.println("Not working");
    }
}