Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:39:24+00:00 2026-06-09T04:39:24+00:00

Unreported exception java.lang.exception : Must be caught or declared to be throw. Why this

  • 0

Unreported exception java.lang.exception : Must be caught or declared to be throw.
Why this problem will occur? Is it some simple method that can help to solve this problems?

I apply this code in my java..

public byte[] encrypt(String message) throws Exception {
    MessageDigest md = MessageDigest.getInstance("md5");
    byte[] digestOfPassword = md.digest("ABCDEABCDE"
                    .getBytes("utf-8"));
    byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
    for (int j = 0, k = 16; j < 8;) {
            keyBytes[k++] = keyBytes[j++];
    }

    SecretKey key = new SecretKeySpec(keyBytes, "DESede");
    IvParameterSpec iv = new IvParameterSpec(new byte[8]);
    Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, key, iv);

    byte[] plainTextBytes = message.getBytes("utf-8");
    byte[] cipherText = cipher.doFinal(plainTextBytes);
    // String encodedCipherText = new sun.misc.BASE64Encoder()
    // .encode(cipherText);

    return cipherText;
}

public String decrypt(byte[] message) throws Exception {
    MessageDigest md = MessageDigest.getInstance("md5");
    byte[] digestOfPassword = md.digest("ABCDEABCDE"
                    .getBytes("utf-8"));
    byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
    for (int j = 0, k = 16; j < 8;) {
            keyBytes[k++] = keyBytes[j++];
    }

    SecretKey key = new SecretKeySpec(keyBytes, "DESede");
    IvParameterSpec iv = new IvParameterSpec(new byte[8]);
    Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
    decipher.init(Cipher.DECRYPT_MODE, key, iv);

    byte[] plainText = decipher.doFinal(message);

    return new String(plainText, "UTF-8");
}

The error is shown in this below part

byte[] pass = encrypt(password);
String pw = new String(pass);

Any idea?
Im using java netbeans to do my project..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:39:27+00:00Added an answer on June 9, 2026 at 4:39 am

    Your encrypt() method throws an Exception. This means that where you’re calling this method, you should explictly throw this Exception or handle it using a try-catch block.

    In your case, for this particular code:

    byte[] pass = encrypt(password);
    String pw = new String(pass);
    

    You should either enclose it in:

    try{
     byte[] pass = encrypt(password);
     String pw = new String(pass);
    }catch(Exception exe){
     //Your error handling code
    }
    

    or declare the method where this code is enclosed with throws Exception.

    • If you are new to exception handling, consider reading this: Lesson: Exceptions from the Java Tutorials

    • Also, here’s another interesting read on “Guidelines on Exception propagation (in Java)”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone know how to fix the following errors unreported exception javax.naming.NamingException; must be caught
If I write this code: Document d = searcher.doc(docId); d.get(latitude) I get unreported exception
I'm a very new to java, just trying to run some simple programs. I
What's wrong with this code import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; /** * *
I'm a java newbie looking for some help reading a file. Here is the
While learning Java I stumble upon this error quite often. It goes like this:
I would like to create a custom exception in Java, how do I do
this is my first attempt to a code doubly linked program in java: This
I am trying to write to a file. I have declared an exception in
class throwseg1 { void show() throws Exception { throw new Exception(my.own.Exception); } void show2()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.