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

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:br.edu.ufsc.eventCrawler.EventByID.java

public void inserirEvento() throws Exception {
    if (eventID == null || eventID.isEmpty()) {
        throw new Exception("Evento em branco!");
    }//w  w w  .  jav a  2 s  .  co  m

    String query = "select eid, name,description, start_time, end_time," + "location, venue from event "
            + "WHERE eid =" + eventID;
    JSONArray fqlEvent = fb.executeFQL(query);
    JSONObject jsonObjectEvent = fqlEvent.getJSONObject(0);
    FacebookEvent event = new FacebookEvent(jsonObjectEvent);
    try {
        FacebookVenue venue = new FacebookVenue(jsonObjectEvent.getJSONObject("venue"));
        event.setVenue(venue);
    } catch (JSONException ex) {
        event.setVenue(new FacebookVenue(jsonObjectEvent));
    }
    events.add(event);
}

From source file:com.marklogic.contentpump.utilities.OptionsFileUtil.java

/**
 * Expands any options file that may be present in the given set of arguments.
 *
 * @param args the given arguments//from   www  .  j  ava2  s. c o  m
 * @return a new string array that contains the expanded arguments.
 * @throws Exception
 */
public static String[] expandArguments(String[] args) throws Exception {
    List<String> options = new ArrayList<String>();

    for (int i = 0; i < args.length; i++) {
        if (args[i].equals(OPTIONS_FILE)) {
            if (i == args.length - 1) {
                throw new Exception("Missing options file");
            }

            String fileName = args[++i];
            File optionsFile = new File(fileName);
            BufferedReader reader = null;
            StringBuilder buffer = new StringBuilder();
            try {
                reader = new BufferedReader(new FileReader(optionsFile));
                String nextLine = null;
                while ((nextLine = reader.readLine()) != null) {
                    nextLine = nextLine.trim();
                    if (nextLine.length() == 0 || nextLine.startsWith("#")) {
                        // empty line or comment
                        continue;
                    }

                    buffer.append(nextLine);
                    if (nextLine.endsWith("\\")) {
                        if (buffer.charAt(0) == '\'' || buffer.charAt(0) == '"') {
                            throw new Exception("Multiline quoted strings not supported in file(" + fileName
                                    + "): " + buffer.toString());
                        }
                        // Remove the trailing back-slash and continue
                        buffer.deleteCharAt(buffer.length() - 1);
                    } else {
                        // The buffer contains a full option
                        options.add(removeQuotesEncolosingOption(fileName, buffer.toString()));
                        buffer.delete(0, buffer.length());
                    }
                }

                // Assert that the buffer is empty
                if (buffer.length() != 0) {
                    throw new Exception(
                            "Malformed option in options file(" + fileName + "): " + buffer.toString());
                }
            } catch (IOException ex) {
                throw new Exception("Unable to read options file: " + fileName, ex);
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException ex) {
                        LOG.info("Exception while closing reader", ex);
                    }
                }
            }
        } else {
            // Regular option. Parse it and put it on the appropriate list
            options.add(args[i]);
        }
    }

    return options.toArray(new String[options.size()]);
}

From source file:it.polimi.deib.rsp_services_csparql.configuration.Config.java

public static Config getInstance() throws Exception {
    if (_instance == null)
        throw new Exception("Please initialize the configuration object at server startup");
    return _instance;
}

From source file:fakedatamaker.contact.online.FakeEmailFactory.java

/**
 * Generates an email, with a given domain name.
 * //from   w  w  w  .j  ava2 s  .  com
 * @param domain
 * @return
 * @throws Exception
 */
public static String makeEmail(String domain) throws Exception {
    if (!isDomainValid(domain)) {
        throw new Exception("Your domain is invalid.");
    }

    return String.format("%s@%s", RandomStringUtils.randomAlphabetic(8), domain);
}

From source file:at.tugraz.sss.serv.SSUri.java

public static List<SSUri> get(final List<String> strings, final String uriPrefix) throws Exception {

    if (strings == null) {
        throw new Exception("pars null");
    }/* w w w  . j a va 2s.  c o m*/

    final List<SSUri> uris = new ArrayList<>();

    for (String string : strings) {
        uris.add(get(string, uriPrefix));
    }

    return uris;
}

From source file:com.netsteadfast.greenstep.util.WsServiceUtils.java

public static Object getServiceByResource(String system, String id) throws ServiceException, Exception {
    if (StringUtils.isBlank(system) || StringUtils.isBlank(id)) {
        throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }//  w w w.  j a  v a2 s.c o m
    SysWsServiceVO wsService = new SysWsServiceVO();
    wsService.setSystem(system);
    wsService.setId(id);
    DefaultResult<SysWsServiceVO> result = sysWsServiceService.findByUK(wsService);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    wsService = result.getValue();
    return getService(wsService.getBeanId(), wsService.getWsdlAddress());
}

From source file:com.artivisi.latihan.web.RoleController.java

@RequestMapping(value = "/role", method = RequestMethod.POST)
public void simpanRole(@RequestBody Role role) throws Exception {
    if (role == null) {
        throw new Exception("Role tidak boleh null");
    }//from  w  w w.  java  2 s  . c  o  m

    roleService.save(role);
}

From source file:com.wrapp.android.webimage.ImageDownloader.java

public static boolean loadImage(final String imageKey, final URL imageUrl) {
    HttpEntity responseEntity = null;/*from w  w w. ja  va  2  s.  co m*/
    InputStream contentInputStream = null;

    try {
        final String imageUrlString = imageUrl.toString();
        if (imageUrlString == null || imageUrlString.length() == 0) {
            throw new Exception("Passed empty URL");
        }
        LogWrapper.logMessage("Requesting image '" + imageUrlString + "'");
        final HttpClient httpClient = new DefaultHttpClient();
        final HttpParams httpParams = httpClient.getParams();
        httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, CONNECTION_TIMEOUT_IN_MS);
        httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT_IN_MS);
        httpParams.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, DEFAULT_BUFFER_SIZE);
        final HttpGet httpGet = new HttpGet(imageUrlString);
        final HttpResponse response = httpClient.execute(httpGet);

        responseEntity = response.getEntity();
        if (responseEntity == null) {
            throw new Exception("No response entity for image: " + imageUrl.toString());
        }
        contentInputStream = responseEntity.getContent();
        if (contentInputStream == null) {
            throw new Exception("No content stream for image: " + imageUrl.toString());
        }

        Bitmap bitmap = BitmapFactory.decodeStream(contentInputStream);
        ImageCache.saveImageInFileCache(imageKey, bitmap);
        LogWrapper.logMessage("Downloaded image: " + imageUrl.toString());
        bitmap.recycle();
    } catch (IOException e) {
        LogWrapper.logException(e);
        return false;
    } catch (Exception e) {
        LogWrapper.logException(e);
        return false;
    } finally {
        try {
            if (contentInputStream != null) {
                contentInputStream.close();
            }
            if (responseEntity != null) {
                responseEntity.consumeContent();
            }
        } catch (IOException e) {
            LogWrapper.logException(e);
        }
    }

    return true;
}

From source file:com.artivisi.salary.payroll.system.controller.BankController.java

@RequestMapping(value = "/bank", method = RequestMethod.POST)
public void saveBank(@RequestBody Bank bank) throws Exception {
    if (bank == null) {
        throw new Exception("Tidak boleh kosong");
    }/*from w  ww .  ja va2 s  .  com*/

    bankService.save(bank);
}

From source file:de.erdesignerng.util.SQLUtils.java

public static void updateViewAttributesFromSQL(View aView, String aStatement) throws Exception {

    ViewAttributeList theList = aView.getAttributes();
    theList.clear();// w  w w.j a  v a 2s.c  o m

    if (StringUtils.isEmpty(aStatement)) {
        throw new Exception("The SQL must not be empty");
    }

    // Remove line breaks and other special characters
    aStatement = aStatement.replace('\t', ' ');
    aStatement = aStatement.replace('\n', ' ');
    aStatement = aStatement.replace('\f', ' ');
    aStatement = aStatement.replace('\r', ' ');

    String theUpperSQL = aStatement.toUpperCase();

    int theSelectStart = theUpperSQL.indexOf(SELECT_CLAUSE);
    int theFromStart = theUpperSQL.indexOf(FROM_CLAUSE);

    if (theSelectStart < 0) {
        throw new Exception("The SQL must contain the SELECT keyword : " + aStatement);
    }
    if (theFromStart < 0) {
        throw new Exception("The SQL must contain the FROM keyword : " + aStatement);
    }
    if (theSelectStart > theFromStart) {
        throw new Exception("Syntax error : " + aStatement);
    }

    String theSelectFields = aStatement.substring(theSelectStart + SELECT_CLAUSE.length(), theFromStart).trim();
    if (StringUtils.isEmpty(theSelectFields)) {
        throw new Exception("No fields are selected : " + aStatement);
    }

    String theCurrentToken = "";
    int p = 0;
    int bracesCounter = 0;
    boolean inString = false;
    while (p < theSelectFields.length()) {

        char theCurrentChar = theSelectFields.charAt(p);
        switch (theCurrentChar) {
        case '(':
            if (!inString) {
                bracesCounter++;
                theCurrentToken += theCurrentChar;
            } else {
                theCurrentToken += theCurrentChar;
            }
            break;
        case ')':
            if (!inString) {
                bracesCounter--;
            } else {
                theCurrentToken += theCurrentChar;
            }
            theCurrentToken += theCurrentChar;
            break;
        case '\"':
            inString = !inString;
            theCurrentToken += theCurrentChar;
            break;
        case '\'':
            inString = !inString;
            theCurrentToken += theCurrentChar;
            break;
        case ',':

            if (bracesCounter == 0 && !inString) {
                addViewAttribute(theCurrentToken.trim(), aView);
                theCurrentToken = "";
            } else {
                theCurrentToken += theCurrentChar;
            }
            break;
        default:
            theCurrentToken += theCurrentChar;
            break;
        }

        p++;
    }

    theCurrentToken = theCurrentToken.trim();
    if (StringUtils.isNotEmpty(theCurrentToken)) {
        addViewAttribute(theCurrentToken, aView);
    }
}