简体   繁体   中英

Creating an Exception class and throwing an unchecked Exception JAVA

Ive been working on an assignment and trying to make make the remaining exception class and for the love of me can not do it. Ive tried throwing it, get an error. Throwing it an catching it and throwing it again and getting an error. Declaring it and getting an error. Declaring it and adding throws to I genuinely just want to understand what I'm doing wrong and how i go about fixing it so the code can compile and work. Basically, I have a Bag interface, a Bag class and we have to also make a custom noObjectException class. If the bag is empty i throw an unchecked exception.

It removes the block that is in the bag the longest. If the array is empty, it throws a NoObjectException.

It throws NoObjectException, if there is no Object to remove(ie it is empty).

If nothing is in the bag structure it will throw NoObjectException.

If nothing is in the bag structure it will throw NoObjectException.

public class NoObjectException extends Exception{

    public NoObjectException(String message){
        super(message);
    }
}

here's the issue the exception needs to be unchecked

<\/blockquote>

Change it to extend a RuntimeException<\/code>


Create a new exception instance each time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM