Java Exceptions List

Sometimes when I write Java code and need to throw an exception, I vaguely remember the exception’s name, but not to the exact spelling. For that, I am compiling this on-going list of exceptions to remind myself.

UPDATE 2013-09-25:

After years of using WordPress to maintain the list, I am moving the list over to a Git repository at BitBucket.org to improve my workflow. You can find that list here.

About these ads

69 thoughts on “Java Exceptions List

  1. Bala

    really it helps lot for me. Is any other exception other than in ur list. if so please update.

    Thanks and keep updating…

  2. wuhrr Post author

    Thank you Sphere, I have added your suggestions. For others: please send me update via comment and I will try my best to keep the list up-to-date.

  3. TC0G

    I’m working on a “Game of Life” program, and I can’t decide what exception to use for a certain method. Here’s the code:

    switch(direction)
    {
    case LEFT:
    // Determine if the pointer cell has any left neighbors
    return (cells[pointer.x-1][pointer.y].state == true);
    case UP:
    // Determine if the pointer cell has any up neighbors
    return (cells[pointer.x][pointer.y-1].state == true);
    case RIGHT:
    // Determine if the pointer cell has any right neighbors
    return (cells[pointer.x+1][pointer.y].state == true);
    case DOWN:
    // Determine if the pointer cell has any right neighbors
    return (cells[pointer.x][pointer.y+1].state == true);
    default:
    System.err.println(“Invalid value for direction”);
    throw new [Exception here];
    return false;
    }

  4. osanda

    hi,
    what exception do i use to catch a terminal window closer.
    this is for thread.sleep function which i want to exit when the window closes.

  5. Hai Post author

    @osanda; This blog only lists the Java Exceptions. For help with your problem, please try the newsgroup or other community-type forums. I wish you good luck.

  6. JavaProgrammer_101

    Hey um thx 4 the awesome list. Just letting u know, its not ArrayOutOfBoundsException, its ArrayIndexOutOfBoundsException. =)

  7. Tim

    javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/SkipPageException

    There’s a couple.

  8. The Beginning Programmer

    Wow this is extremely helpful. Thanks a million! Isn’t it amazing that people are still thanking you almost 3 years after your post? I think it’s really cool.

    Also another Exception is the: NullPointerException

    it’s great when using the JOptionPane class.

    If at all possible, just delete my last comment. I used my friends name and he got mad at me for it. So if it’s possible it would be appreciated.

  9. SoboLAN

    I have a lot of projects to implement in Java at this time (computer science college) and this list of exceptions was extremely useful (I don’t remember most of them… because I don’t use them every day).

    Thank you.

  10. Hai Post author

    @ tshegofatso: If you have any specific exception that I missed, I will be glad to add it to the list.

  11. Pingback: Welcome! « Zéphyrin Soh

  12. gcbenison

    Philosophical question regarding TcoG’s example: is it better to use the stock IllegalArgumentException, or to create a subclass IllegalDirectionException? One could also add bounds checking to the example, in which it should really throw two kinds of exception: one for out-of-bounds, and one for meaningless ‘direction’ arguments.

  13. Hai Post author

    @gcbenison: Please direct your questions to stackoverflow.com or elsewhere as this blog post is narrowly focusing on a list of Java exceptions and nothing else.

  14. Hai Post author

    @Matthijs: Yes, all of us can do that, but please read my first paragraph of this post for my rationale.

  15. Matthijs

    Ok, but…the subclass list on the Java API also contains the exact spelling, right? You don’t need to search for the exception you’re looking for, just bookmark the main exception classes and then check their subclass list. This also allows you to immediately find out a description of the exception, plus the API list is exhaustive and automatically kept up-to-date. Anyway, it was just a suggestion, whatever works best for you.

  16. Chris R

    This is helpful. Might want to add Exception . Since this one seems to get all the known ones at the same time for some reason. It’s helpful but cuts down on learning them. :D

  17. justtherabidrabbit

    there is the FishFaceException, which comes up when a RoBoTX is not connected to the computer by bluetooth properly
    I encountered it while trying to program my robot this semester

  18. Hai Post author

    @ justtherabidrabbit: What a unique (and rare) exception, but who am I to discriminate; so I added that exception to the list. Thank you.

  19. javacrazzy

    Thanks a lot it helped me a lot i am working on creating a api that maps the exceptions and shows a meaningful messages.
    If there are any suggestions do update me

  20. Hai Post author

    @n8chz: the Java doc suggests to:

    throw new java.lang.ArithmeticException(“divide by zero”);

  21. Java Dev

    I really can’t understand what for did you publish the list with exception names. When you are developing something you are using some IDE and you can use syntax tips in any time. In this way you shouldn’t care about the exception names

  22. Chris R

    Wonder what the fastest way to cause all the exceptions we’d need to check for on a given day is? O_o My Guess would be to use Exception in combination with getClass(). It’s strange though how the Java API doesn’t list all of these. XD

  23. Louvenia

    Thanks for your personal marvelous posting! I seriously enjoyed reading it, you
    will be a great author.I will remember to bookmark your blog and may come back down
    the road. I want to encourage that you continue your great job, have a nice afternoon!

  24. Philomena

    I blog quite often and I genuinely thank you for
    your content. This article has really peaked my interest.
    I will take a note of your site and keep checking for new information about once
    a week. I opted in for your RSS feed as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s