Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: [HELP] unreported exceptions

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question [HELP] unreported exceptions

    hello there, i would like to ask is there a way to throw away all exception as i have errors of unreported exception everywhere and how to i get a key out from the object after casting it into an object.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: [HELP] unreported exceptions

    Quote Originally Posted by Paytheprice View Post
    hello there, i would like to ask is there a way to throw away all exception
    You could wrap a block of code in a try / catch block and in the catch section, catch Exception and ignore it. I strongly urge you *NOT* to do this unless you also enjoy driving a motorcycle with a blindfold on and have your organ donor card with you.

    as i have errors of unreported exception everywhere and how to i get a key out from the object after casting it into an object.
    Perhaps we can better help you if you post your code and your exception messages.

  3. The Following User Says Thank You to curmudgeon For This Useful Post:

    copeg (January 26th, 2013)

  4. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: [HELP] unreported exceptions

    Quote Originally Posted by curmudgeon View Post
    You could wrap a block of code in a try / catch block and in the catch section, catch Exception and ignore it. I strongly urge you *NOT* to do this unless you also enjoy driving a motorcycle with a blindfold on and have your organ donor card with you.



    Perhaps we can better help you if you post your code and your exception messages.

    sorry for the double posting as when i came back to the old post it disappeared from where i put it and well, i couldnt find it. do i wrap the whole thing in a try /catch or catch them one by one?

     
    myClient.java:34: error: unreported exception CertificateException; must be caug
    ht or declared to be thrown
    CertificateFactory certfac = CertificateFactory.getInstance("X.509");
                                                               ^
    myClient.java:36: error: unreported exception FileNotFoundException; must be cau
    ght or declared to be thrown
            FileInputStream CA = new FileInputStream ("ca.cer");
                                 ^
    myClient.java:37: error: unreported exception CertificateException; must be caug
    ht or declared to be thrown
            Certificate CACert = certfac.generateCertificate(CA);
                                                            ^
    myClient.java:38: error: unreported exception IOException; must be caught or dec
    lared to be thrown
            CA.close();
                    ^
    myClient.java:44: error: unreported exception FileNotFoundException; must be cau
    ght or declared to be thrown
                            FileInputStream server = new FileInputStream (serveruser
    +".cer");
                                                     ^
    myClient.java:45: error: unreported exception CertificateException; must be caug
    ht or declared to be thrown
                    Certificate serverCert = certfac.generateCertificate(server);
                                                                        ^
    myClient.java:51: error: unreported exception IOException; must be caught or dec
    lared to be thrown
    while ((nRead = server.read(data, 0, data.length)) != -1) {
                               ^
    myClient.java:54: error: unreported exception IOException; must be caught or dec
    lared to be thrown
    buffer.flush();
                ^
    myClient.java:55: error: unreported exception IOException; must be caught or dec
    lared to be thrown
            server.close();
                        ^
    myClient.java:63: error: unreported exception FileNotFoundException; must be cau
    ght or declared to be thrown
     FileInputStream fis = new FileInputStream(file);
                           ^
    myClient.java:64: error: unreported exception IOException; must be caught or dec
    lared to be thrown
     fis.read(sigBytes);
             ^
    myClient.java:65: error: unreported exception IOException; must be caught or dec
    lared to be thrown
     fis.close();
              ^
    myClient.java:66: error: unreported exception Exception; must be caught or decla
    red to be thrown
            boolean veri=verifySig(data,CACertPub,sigBytes);
                                  ^
    myClient.java:76: error: unreported exception FileNotFoundException; must be cau
    ght or declared to be thrown
                                    RandomAccessFile raf = new RandomAccessFile(clie
    ntuser+".pk8", "r");
                                                           ^
    myClient.java:77: error: unreported exception IOException; must be caught or dec
    lared to be thrown
    byte[] buf = new byte[(int)raf.length()];
                                         ^
    myClient.java:78: error: unreported exception IOException; must be caught or dec
    lared to be thrown
    raf.readFully(buf);
                 ^
    myClient.java:79: error: unreported exception IOException; must be caught or dec
    lared to be thrown
    raf.close();
             ^
    myClient.java:81: error: unreported exception NoSuchAlgorithmException; must be
    caught or declared to be thrown
    KeyFactory kf = KeyFactory.getInstance("RSA");
                                          ^
    myClient.java:82: error: unreported exception InvalidKeySpecException; must be c
    aught or declared to be thrown
    PrivateKey ClientPriv = kf.generatePrivate(kspec);
                                              ^
    myClient.java:92: error: unreported exception IOException; must be caught or dec
    lared to be thrown
      out = new ObjectOutputStream(bos);
            ^
    myClient.java:93: error: unreported exception IOException; must be caught or dec
    lared to be thrown
      out.writeObject(Aesobj);
                     ^
    myClient.java:95: error: unreported exception IOException; must be caught or dec
    lared to be thrown
      out.close();
               ^
    myClient.java:96: error: unreported exception IOException; must be caught or dec
    lared to be thrown
      bos.close();
               ^
    myClient.java:99: error: unreported exception IOException; must be caught or dec
    lared to be thrown
                    streamOut.writeUTF(asHex(aessend));
                                      ^
    myClient.java:100: error: unreported exception Exception; must be caught or decl
    ared to be thrown
                    byte[] signatureaes=signData(aessend,ClientPriv);
                                                ^
    myClient.java:101: error: unreported exception IOException; must be caught or de
    clared to be thrown
                    streamOut.writeUTF(AESEncrypt(AESKey,asHex(signatureaes)));
                                      ^
    myClient.java:113: error: unreported exception Exception; must be caught or decl
    ared to be thrown
                    byte[] signature=signData(encryptedline.getBytes(),ClientPriv);
                                             ^
    myClient.java:162: error: unreported exception NoSuchAlgorithmException; must be
     caught or declared to be thrown
      KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
                                                          ^
    myClient.java:178: error: unreported exception NoSuchAlgorithmException; must be
     caught or declared to be thrown
      Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
                                        ^
    myClient.java:179: error: unreported exception InvalidKeyException; must be caug
    ht or declared to be thrown
      cipher.init(Cipher.ENCRYPT_MODE,ClientPriv);
                 ^
    myClient.java:180: error: unreported exception IllegalBlockSizeException; must b
    e caught or declared to be thrown
      byte[] firstcipher=cipher.doFinal(Aestxt);
                                       ^
    myClient.java:181: error: unreported exception InvalidKeyException; must be caug
    ht or declared to be thrown
      cipher.init(Cipher.ENCRYPT_MODE,ServerPub);
                 ^
    myClient.java:182: error: unreported exception IllegalBlockSizeException; must b
    e caught or declared to be thrown
      byte[] seccipher= cipher.doFinal(firstcipher);
                                      ^
    myClient.java:190: error: unreported exception NoSuchAlgorithmException; must be
     caught or declared to be thrown
      Cipher c = Cipher.getInstance("AES");
                                   ^
    myClient.java:192: error: unreported exception InvalidKeyException; must be caug
    ht or declared to be thrown
    c.init(Cipher.ENCRYPT_MODE, AESKey);
          ^
    myClient.java:194: error: unreported exception IllegalBlockSizeException; must b
    e caught or declared to be thrown
    byte[] ciphertxt=c.doFinal(Ptxt);
                              ^
    Note: myClient.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    36 errors

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: [HELP] unreported exceptions

    You need to evaluate each exception and see what the code should do when or if it is thrown.
    Those you can recover from and retry the logic say when the user enters bad data and you want to try it again
    and those that mean the program can't continue where you'll issue an error message and exit the program.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Create your own Exceptions!
    By newbie in forum Java Programming Tutorials
    Replies: 3
    Last Post: September 6th, 2013, 11:51 AM
  2. Always Catch Exceptions
    By Tjstretch in forum Java Programming Tutorials
    Replies: 2
    Last Post: October 27th, 2011, 02:26 PM
  3. throws Exceptions
    By beruska in forum Exceptions
    Replies: 1
    Last Post: October 25th, 2011, 02:25 PM
  4. Replies: 6
    Last Post: March 25th, 2011, 03:42 PM