No exception of type Exception can be thrown, an exception type must be a subclass of Throwable

no exception of type configurationexception can be thrown;
no exception of type sdkexception can be thrown
how to throw an exception in java
throwing your own exception in java
catch and throw exception java
throws throwable
when should a function throw an exception
exception handling program in java with output

I was seaching this problem in other questions but still didn't figure out what does exactly mean Throwable. Read a few articles about it (its superclas bla bla bla) but still don't know how to implement it. Forgot to mention i am new to java. Any advice would be gratefully accepted :D

Here is the Exception class:

class Exception {
private int pDen;
private int pMes;
private int kDen;
private int kMes;

public Exception(int pDen, int pMes, int kDen, int kMes) {
    super();
    this.pDen = pDen;
    this.pMes = pMes;
    this.kDen = kDen;
    this.kMes = kMes;
}
public void message()
{
    System.out.println("Isklucok");
}
public void promena()
{
    int tmpDen = 0;
    int tmpMes = 0;
    tmpDen = pDen;
    pDen = kDen;
    kDen = tmpDen;
    tmpMes = pMes;
    pMes = kMes;
    kMes = tmpMes;
}

}

And here is the code that i run in other class where shoud i catch my exception where is thrown.

try {
        if(pMes > kMes)
        {
            throw new Exception(pDen,pMes,kDen,kMes);
        }
        else if(pMes == kMes)
            if(pDen > kDen)
            {
                throw new Exception(pDen,pMes,kDen,kMes);
            }
    }
    catch(Exception e)
    {
        e.message();
        e.promena();
    }

Make your custom exception extends something from the Throwable hierarchy.

For example

// Exception here is java.lang.Exception, not the class from your example
public class MyException extends Exception {

    // ...

}

No exception of type DataAccessException can be thrown; an , It has a error, "No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable". I can't understand  No exception of type MarshalException can be thrown; an exception type must be a subclass of Throwable The method printStackTrace() is undefined for the type MarshalException No exception of type ValidationException can be thrown; an exception type must be a subclass of Throwable The method printStackTrace() is undefined for the type ValidationException.

"No exception of type SomeException can be thrown; an Exception , EJB project. JBDS shows the error: No exception of type EmailException can be thrown; an Exception type must be a subclass of Throwable  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more No exception of type AxisFault can be thrown; an exception type must be a subclass of Throwable

Please ignore the answers suggesting you implement your own Exception class. Java has its own: java.lang.Exception. Just use that, and extend it if needed. Cases where it makes sense to have your own Throwable, but not extend from the standard Exception are very rare.

522327 – [9] Bogus error "No exception of type IOException can be , ERROR in nonmodular\ProblemWithThrowable.java (at line 7) public void can be thrown; an exception type must be a subclass of Throwable ----------. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more No exception of type UnderflowException can be thrown;

You'll have to create a custom Exception class containing the required Constructors as follows:

public class CustomException extends Exception {
    /* Optional: Include Serial UID */

    public CustomException(Throwable t) {
        super(t);
    }

    public CustomException(int pDen, int pMes, int kDen, int kMes) {
        /* Handle Info & Throw Exception */
    }

}

And then you can throw the exception as follows,

throw new CustomException(pDen,pMes,kDen,kMes);

Exceptions in Java, Part 1: Exception handling basics, Throwing, trying, catching, and cleaning up after Java exceptions Java exceptions are library types and language features used to represent You should never try to handle errors yourself because the JVM might not be able to recover from it. Only objects created from Throwable and its subclasses can be thrown (and  This is quite easy to do: just define a subclass of Exception (a subclass of Throwable). Your subclasses do not need to actually implement anything, it is their existence in the type system which allows you to use them as exceptions. Java Exception Class. The Exception class does not define any methods of

Points to avoid this common error while writing any Java program:

  1. Make sure you are not importing any package for Exception class.
  2. If you find any import for this remove it.
  3. You can implement by extending Exception class.
  4. Or by throwing an Exception from the method.
  5. Use throw when creating a custom message to be thrown along with throws keyword on method.

No exception of type SDKException can be thrown; an exception , Error is as below -. No exception of type SDKException can be thrown; an exception type must be subclass of Throwable. Thanks in advance. 3. Throwable is the superclass of Exception and Error. Of the three classes, I would consider Exception to be the most suitable one for the task. Most people write try-catch blocks that look out only for Exception and its subclasses; they will not be able to handle a new Throwable ().

Throwable (Java Platform SE 7 ), The Throwable class is the superclass of all errors and exceptions in the Java Similarly, only this class or one of its subclasses can be the argument type in layer without changing its API (in particular, the set of exceptions thrown by its methods). Subclasses of Throwable should document any conditions under which  No exception of type Exception can be thrown, an exception type must be a subclass of Throwable. Ask Question. Asked 1 year, 3 months ago. Active 6 months ago. Viewed 5k times. 0. I was seaching this problem in other questions but still didn't figure out what does exactly mean Throwable.

How to Throw Exceptions (The Java™ Tutorials > Essential Classes , Before you can catch an exception, some code somewhere must throw one. Regardless of what throws the exception, it's always thrown with the throw statement. the various types of exceptions that can occur during the execution of a program. Throwable objects are instances of any subclass of the Throwable class. Your PartInitException is not in the classpath hence the compiler can not determine if it is an exception and of what kind. Have a look here as well for a similar problem: No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable

Interactive Object-Oriented Programming in Java: Learn and Test , An exception type must be a subclass of Throwable To remove the errors in the previous program, you can follow the compiler's suggestion. For example, in this​  No exception of type BPMIdentityNotFoundException can be thrown; an exception type must be a subclass of Throwable. vo12 Aug 13, 2013 11:36 AM How to solve this exception.

Comments
  • Why create your own exception class instead of using eg IllegalArgumentException or IllegalStateException?