Example usage for java.lang IllegalArgumentException printStackTrace

List of usage examples for java.lang IllegalArgumentException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    try {/*from  w w w . j a va2  s  .c om*/
        URL url = new URI("").toURL();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:TraceLevel.java

public static void main(String... args) {
    TraceLevel newLevel = TraceLevel.valueOf(args[0]);

    try {/*w w w  .ja  v  a  2 s .  c o  m*/
        MyServer svr = new MyServer();
        Class<?> c = svr.getClass();
        Field f = c.getDeclaredField("level");
        f.setAccessible(true);
        TraceLevel oldLevel = (TraceLevel) f.get(svr);
        out.format("Original trace level:  %s%n", oldLevel);

        if (oldLevel != newLevel) {
            f.set(svr, newLevel);
            out.format("    New  trace level:  %s%n", f.get(svr));
        }

        // production code should handle these exceptions more gracefully
    } catch (IllegalArgumentException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (NoSuchFieldException x) {
        x.printStackTrace();
    }
}

From source file:ArrayTroubleAgain.java

public static void main(String... args) {
    Integer[] ary = new Integer[2];
    try {// ww w .j  a v a 2 s. c  o  m
        Array.setInt(ary, 0, 1); // IllegalArgumentException

        // production code should handle these exceptions more gracefully
    } catch (IllegalArgumentException x) {
        err.format("Unable to box%n");
    } catch (ArrayIndexOutOfBoundsException x) {
        x.printStackTrace();
    }
}

From source file:adapter.tdb.sync.clients.GetVocabularyOfMagicDrawAdapterAndPushToStore.java

public static void main(String[] args) {

    Thread thread = new Thread() {
        public void start() {

            URI vocabURI = URI.create("http://localhost:8080/oslc4jmagicdraw/services/sysml-rdfvocabulary");

            // create an empty RDF model
            Model model = ModelFactory.createDefaultModel();

            // use FileManager to read OSLC Resource Shape in RDF
            //            String inputFileName = "file:C:/Users/Axel/git/EcoreMetamodel2OSLCSpecification/EcoreMetamodel2OSLCSpecification/Resource Shapes/Block.rdf";
            //            String inputFileName = "file:C:/Users/Axel/git/ecore2oslc/EcoreMetamodel2OSLCSpecification/RDF Vocabulary/sysmlRDFVocabulary of OMG.rdf";
            //            InputStream in = FileManager.get().open(inputFileName);
            //            if (in == null) {
            //               throw new IllegalArgumentException("File: " + inputFileName
            //                     + " not found");
            //            }

            // create TDB dataset
            String directory = TriplestoreUtil.getTriplestoreLocation();
            Dataset dataset = TDBFactory.createDataset(directory);
            Model tdbModel = dataset.getDefaultModel();
            try {

                HttpGet httpget = new HttpGet(vocabURI);
                httpget.addHeader("accept", "application/rdf+xml");
                CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpResponse response = httpClient.execute(httpget);
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    InputStream inputStream = entity.getContent();
                    model.read(inputStream, null);
                    tdbModel.add(model);
                }/*from www. ja  v  a 2s .c o  m*/

            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            tdbModel.close();
            dataset.close();
        }
    };
    thread.start();
    try {
        thread.join();
        System.out.println("Vocabulary of OSLC MagicDraw SysML adapter added to triplestore");
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:it.txt.ens.core.impl.BasicENSResource.java

public static void main(String[] args) {
    try {//  w  w w  .ja  va  2  s. c  o m
        ENSResource r = ENSResourceURIParser.parse(new URI(
                "amqp://www.iot-at-work.eu/ENS?Namespace=Demo+IoTatWork+Namespace&Pattern=DemoIoTatWork.Turin.CRFPlant.WeldingCell1.%23.Energy"),
                new BasicENSResourceFactory());
        System.out.println(r.getPattern());
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URIParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:net.timewalker.ffmq4.FFMQServerLauncher.java

/**
 * Main//  ww  w  .  ja v a2s.  c  om
 */
public static void main(String[] args) {
    try {
        setupSystemProperties();
        Settings settings = parseCommandLine(args);

        // Create a server instance
        FFMQServer server = new FFMQServer("engine1", settings);
        Runtime.getRuntime().addShutdownHook(new ShutdownHook(server));

        // Start server
        server.run();

        System.exit(0);
    } catch (IllegalArgumentException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-2);
    }
}

From source file:com.cubeia.games.poker.CreateUser.java

public static void main(String[] args) {
    CreateUser action = new CreateUser();
    try {/*from w  ww. jav  a2s. co  m*/
        Args.parse(action, args);
        action.execute();
    } catch (IllegalArgumentException e) {
        Args.usage(action);
    } catch (Exception e) {
        System.out.println("!!! FAILURE !!!");
        e.printStackTrace();
    }
}

From source file:com.kylinolap.metadata.tool.HiveSourceTableMgmt.java

/**
 * @param args//from   w  ww.  ja  v a2  s .c  om
 *            HiveSourceTableMgmt jdbc:hive2://kylin-local:10000/default,
 *            hive, hive, c:\\temp [, name]
 */
public static void main(String[] args) {
    if (args.length < 3) {
        System.out.println("Wrong arguments, example");
        System.out.println("Get data from command: -c Kylin*, c:\\temp");
        System.out.println("Get data from outputfile: -f /tmp/hiveout.txt, c:\\temp");
        System.exit(1);
    }
    String mode = args[0];
    String tableMetaOutcomeDir = args[2];
    HiveSourceTableMgmt rssMgmt = new HiveSourceTableMgmt();
    try {

        if (mode.equalsIgnoreCase("-c")) {
            rssMgmt.extractTableDescWithTablePattern(args[1], tableMetaOutcomeDir);
        }

        if (mode.equalsIgnoreCase("-f")) {
            rssMgmt.extractTableDescFromFile(args[1], tableMetaOutcomeDir);
        }

    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
}

From source file:de.uniko.west.winter.test.basics.JenaTests.java

public static void main(String[] args) {

    Model newModel = ModelFactory.createDefaultModel();
    //      //from   w  ww  . j  a  va 2s  .c  o  m
    Model newModel2 = ModelFactory.createModelForGraph(ModelFactory.createMemModelMaker().getGraphMaker()
            .createGraph("http://www.defaultgraph.de/graph1"));
    StringBuilder updateString = new StringBuilder();
    updateString.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>");
    updateString.append("PREFIX xsd: <http://bla.org/dc/elements/1.1/>");
    updateString.append("INSERT { ");
    updateString.append(
            "<http://example/egbook1> dc:title  <http://example/egbook1/#Title1>, <http://example/egbook1/#Title2>. ");
    //updateString.append("<http://example/egbook1> dc:title  \"Title1.1\". ");
    //updateString.append("<http://example/egbook1> dc:title  \"Title1.2\". ");
    updateString.append("<http://example/egbook21> dc:title  \"Title2\"; ");
    updateString.append("dc:title  \"2.0\"^^xsd:double. ");
    updateString.append("<http://example/egbook3> dc:title  \"Title3\". ");
    updateString.append("<http://example/egbook4> dc:title  \"Title4\". ");
    updateString.append("<http://example/egbook5> dc:title  \"Title5\". ");
    updateString.append("<http://example/egbook6> dc:title  \"Title6\" ");
    updateString.append("}");

    UpdateRequest update = UpdateFactory.create(updateString.toString());
    UpdateAction.execute(update, newModel);

    StmtIterator iter = newModel.listStatements();
    System.out.println("After add");
    while (iter.hasNext()) {
        System.out.println(iter.next().toString());

    }

    StringBuilder constructQueryString = new StringBuilder();
    constructQueryString.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>");
    constructQueryString.append("CONSTRUCT {?sub dc:title <http://example/egbook1/#Title1>}");
    constructQueryString.append("WHERE {");
    constructQueryString.append("?sub dc:title <http://example/egbook1/#Title1>");
    constructQueryString.append("}");

    StringBuilder askQueryString = new StringBuilder();
    askQueryString.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>");
    askQueryString.append("ASK {");
    askQueryString.append("?sub dc:title <http://example/egbook1/#Title1>");
    askQueryString.append("}");

    StringBuilder selectQueryString = new StringBuilder();
    selectQueryString.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>");
    selectQueryString.append("SELECT * ");
    selectQueryString.append("WHERE {");
    selectQueryString.append("?sub ?pred ?obj");
    selectQueryString.append("}");

    Query cquery = QueryFactory.create(constructQueryString.toString());
    System.out.println(cquery.getQueryType());
    Query aquery = QueryFactory.create(askQueryString.toString());
    System.out.println(aquery.getQueryType());
    Query query = QueryFactory.create(selectQueryString.toString());
    System.out.println(query.getQueryType());
    QueryExecution queryExecution = QueryExecutionFactory.create(query, newModel);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    URI test = null;
    try {
        test = new URI("http://bla.org/dc/elements/1.1/double");
    } catch (URISyntaxException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    System.out.println(test.getPath().toString().substring(test.getPath().lastIndexOf("/") + 1));
    System.out.println("java.lang."
            + test.getPath().toString().substring(test.getPath().lastIndexOf("/") + 1).substring(0, 1)
                    .toUpperCase()
            + test.getPath().toString().substring(test.getPath().lastIndexOf("/") + 1).substring(1));

    String typ = "java.lang.Boolean";
    String val = "true";

    try {
        Object typedLiteral = Class.forName(typ, true, ClassLoader.getSystemClassLoader())
                .getConstructor(String.class).newInstance(val);

        System.out.println("Type: " + typedLiteral.getClass().getName() + " Value: " + typedLiteral);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        System.out.println("Query...");
        com.hp.hpl.jena.query.ResultSet results = queryExecution.execSelect();
        System.out.println("RESULT:");
        ResultSetFormatter.output(System.out, results, ResultSetFormat.syntaxJSON);
        //         
        //         
        //         ResultSetFormatter.outputAsJSON(baos, results);
        //         System.out.println(baos.toString());
        //         System.out.println("JsonTest: ");
        //         JSONObject result = new JSONObject(baos.toString("ISO-8859-1"));
        //         for (Iterator key = result.keys(); result.keys().hasNext(); ){
        //            System.out.println(key.next());
        //            
        //            for (Iterator key2 = ((JSONObject)result.getJSONObject("head")).keys(); key2.hasNext(); ){
        //               System.out.println(key2.next());
        //            }
        //         }

        //         Model results = queryExecution.execConstruct();

        //         results.write(System.out, "TURTLE");
        //         for ( ; results.hasNext() ; ){
        //            QuerySolution soln = results.nextSolution() ;
        //            RDFNode x = soln.get("sub") ;   
        //            System.out.println("result: "+soln.get("sub")+" hasTitle "+soln.get("obj"));
        //             Resource r = soln.getResource("VarR") ; 
        //             Literal l = soln.getLiteral("VarL") ; 
        //
        //         }

    } catch (Exception e) {
        // TODO: handle exception
    }

    //      StringBuilder updateString2 = new StringBuilder();
    //      updateString2.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>");
    //      updateString2.append("DELETE DATA { ");
    //      updateString2.append("<http://example/egbook3> dc:title  \"Title3\" ");
    //      updateString2.append("}");
    //
    //      UpdateAction.parseExecute(updateString2.toString(), newModel);
    //      
    //      iter = newModel.listStatements();
    //      System.out.println("After delete");
    //      while (iter.hasNext()) {
    //         System.out.println(iter.next().toString());
    //            
    //      }
    //      
    //      StringBuilder updateString3 = new StringBuilder();
    //      updateString3.append("PREFIX dc: <http://purl.org/dc/elements/1.1/>");
    //      updateString3.append("DELETE DATA { ");
    //      updateString3.append("<http://example/egbook6> dc:title  \"Title6\" ");
    //      updateString3.append("}");
    //      updateString3.append("INSERT { ");
    //      updateString3.append("<http://example/egbook6> dc:title  \"New Title6\" ");
    //      updateString3.append("}");
    //   
    //      UpdateAction.parseExecute(updateString3.toString(), newModel);

    //      UpdateAction.parseExecute(   "prefix exp: <http://www.example.de>"+
    //                           "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
    //                           "INSERT { graph <http://www.defaultgraph.de/graph1> {"+
    //                           "   <http://www.test.de#substructure1> <exp:has_relation3> <http://www.test.de#substructure2> ."+ 
    //                           "   <http://www.test.de#substructure1> <rdf:type> <http://www.test.de#substructuretype1> ."+ 
    //                           "   <http://www.test.de#substructure2> <rdf:type> <http://www.test.de#substructuretype2> ."+
    //                           "}}", newModel2);
    //      
    //      iter = newModel.listStatements();
    //      System.out.println("After update");
    //      while (iter.hasNext()) {
    //         System.out.println(iter.next().toString());
    //            
    //      }
}

From source file:io.seldon.importer.articles.FileItemAttributesImporter.java

/**
 * @param args/*from w w  w  . j  a va2  s.co  m*/
 * @throws InterruptedException 
 * @throws FileNotFoundException 
 */
public static void main(String[] args) throws InterruptedException, FileNotFoundException {

    FailFast failFast = new FailFast(Thread.currentThread());
    { // Fail Fast thread
        Thread fail_fast_thread = new Thread(failFast);
        fail_fast_thread.setName("fail_fast_thread");
        fail_fast_thread.start();
    }

    try {
        Args.parse(FileItemAttributesImporter.class, args);

        DefaultApiClient client = new DefaultApiClient(apiUrl, consumerKey, consumerSecret, API_TIMEOUT);

        FileItemAttributesImporter fixer = new FileItemAttributesImporter(client);

        fixer.setFailFast(failFast);
        fixer.run();

    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        Args.usage(FileItemAttributesImporter.class);
    }
}