Unreported exception java.lang.Exception; must be caught or declared to be thrown

We Are Going To Discuss About Unreported exception java.lang.Exception; must be caught or declared to be thrown . So lets Start this Java Article.

Unreported exception java.lang.Exception; must be caught or declared to be thrown

Advertisements
  1. Unreported exception java.lang.Exception; must be caught or declared to be thrown

    In your main method, the call to m16h may lead to an exception being thrown. In this case, you have two choices:
    handle the exception yourself in the main method.

  2. Unreported exception java.lang.Exception; must be caught or declared to be thrown

    In your main method, the call to m16h may lead to an exception being thrown. In this case, you have two choices:
    handle the exception yourself in the main method.

Solution 1

Advertisements

public static byte[] m16h(byte[] m) throws Exception

The signature of your method indicates that an Exception is susceptible of being thrown.

This means that the exception either :

  1. Must be handled by the caller

    try {
        System.out.println(xor(m16h(add(xor(xor(m16h(add(k1, m16h(add(k2, m16h(k3))))), k3), k2), k1)), k3));
    } catch (Exception e) {
        e.printStackTrace();
    }
    
  2. Must be rethrowed by the caller

    public static void main(String[] args) throws Exception
    

Original Author Yassin Hajaj Of This Content

Solution 2

Advertisements

In your main method, the call to m16h may lead to an exception being thrown. In this case, you have two choices:

  • handle the exception yourself in the main method.
// in the main
try {
    System.out.println(xor(m16h(...));
} catch(Exception e) {
    // do something, e.g. print e.getMessage()
}
  • indicate that the main method can throw an exception, by appending throws Exception to its declaration.

public static void main(String args[]) throws Exception

Original Author christophetd Of This Content

Solution 3

Advertisements

Surround the line where you call this method with a try/catch block as follows:

try {
  System.out.println(xor(m16h(add(xor(xor(m16h(add(k1, m16h(add(k2, m16h(k3))))), k3), k2), k1)), k3));
}catch (Exception e){
  System.out.println (e.getMessage());
}

Original Author SCouto Of This Content

Conclusion

Advertisements

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment