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.
AWTException
AclNotFoundException
ActivationException
AlreadyBoundException
ApplicationException
ArithmeticException
ArrayIndexOutOfBoundsException
AssertionException
BackingStoreException
BadAttributeValueExpException
BadBinaryOpValueExpException
BadLocationException
BadStringOperationException
BatchUpdateException
BrokenBarrierException
CertificateException
ChangedCharSetException
CharConversionException
CharacterCodingException
ClassNotFoundException
CloneNotSupportedException
ClosedChannelException
DataFormatException
DatatypeConfigurationException
DestroyFailedException
EOFException
Exception
ExecutionException
ExpandVetoException
FileLockInterruptionException
FileNotFoundException
FishFaceException
FontFormatException
GSSException
GeneralSecurityException
IIOException
IOException
IllegalAccessException
IllegalArgumentException
IllegalClassFormatException
IllegalStateException
IndexOutOfBoundsException
InputMismatchException
InstantiationException
InterruptedException
InterruptedIOException
IntrospectionException
InvalidApplicationException
InvalidMidiDataException
InvalidPreferencesFormatException
InvalidTargetObjectTypeException
InvocationTargetException
JAXBException
JMException
KeySelectorException
LastOwnerException
LineUnavailableException
MalformedURLException
MarshalException
MidiUnavailableException
MimeTypeParseException
NamingException
NegativeArraySizeException
NoSuchElementException
NoSuchFieldException
NoSuchMethodException
NoninvertibleTransformException
NotBoundException
NotOwnerException
NullPointerException
NumberFormatException
ObjectStreamException
ParseException
ParserConfigurationException
PrintException
PrinterException
PrivilegedActionException
PropertyVetoException
ProtocolException
RefreshFailedException
RemarshalException
RemoteException
RuntimeException
SAXException
SOAPException
SQLException
SQLWarning
SSLException
ScriptException
ServerNotActiveException
SocketException
SyncFailedException
TimeoutException
TooManyListenersException
TransformException
TransformerException
URIReferenceException
URISyntaxException
UTFDataFormatException
UnknownHostException
UnknownServiceException
UnmodifiableClassException
UnsupportedAudioFileException
UnsupportedCallbackException
UnsupportedEncodingException
UnsupportedFlavorException
UnsupportedLookAndFeelException
UnsupportedOperationException
UserException
XAException
XMLParseException
XMLSignatureException
XMLStreamException
XPathException
ZipException
unr303
November 29, 2007
That’s helped. Thanks.
Bala
January 25, 2008
really it helps lot for me. Is any other exception other than in ur list. if so please update.
Thanks and keep updating…
Mark
September 17, 2008
Thanks for the list. Add NoSuchElement (used with collections) to your list.
Sphere
October 16, 2008
some more….
NumberFormatException
ArrayOutOfBoundsException
NegativeArraySizeException
wuhrr
October 16, 2008
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.
Rubens Mariuzzo
October 16, 2008
Thanks
TC0G
January 2, 2009
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;
}
TC0G
January 2, 2009
Can you help me? Thanks.
Stan
January 5, 2009
IllegalArgumentException…also a common one.
Hai
January 6, 2009
To TC0G: I suggest UnsupportedOperationException, or you can define your own exception.
Hai
January 6, 2009
Stan: Thank you for your excellent suggestion. I have added IllegalArgumentException to the list.
Hai
January 6, 2009
How about UnsupportedOperationException?
Marcelo
July 29, 2009
It helped a lot. tks!
egasimus
August 29, 2009
ArithmeticException?
Hai
September 3, 2009
@egasimus:I updated my post with your suggestion. Thanks.
RR
September 22, 2009
Where’s the AssertionException & the URLBlockException ?
But anyways thanks – it helped !
Hai
September 22, 2009
@RR – I added AssertionException, but did not find any info on URLBlockException. Did you misspelled it?
;erwin ualat
November 10, 2009
can someone create a short program with me.. like calculator
Matt
November 23, 2009
Helpful list.
One you missed:
IllegalStateException
Also, you might want to consider dividing the list into checked and unchecked exceptions (http://java.sun.com/docs/books/tutorial/essential/exceptions/catchOrDeclare.html).
Hai
November 24, 2009
Thank you Matt, I have added IllegalStateException to the list
osanda
March 2, 2010
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.
Hai
March 4, 2010
@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.
Karl
March 6, 2010
NoSuchElement should be NoSuchElementException
Hai
March 7, 2010
@Karl: Thank you. I updated my list.
JavaProgrammer_101
May 20, 2010
Hey um thx 4 the awesome list. Just letting u know, its not ArrayOutOfBoundsException, its ArrayIndexOutOfBoundsException. =)
Hai
May 20, 2010
@ JavaProgrammer_101: Right on. I got it fixed. Thank you.
Tim
November 4, 2010
javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/jsp/SkipPageException
There’s a couple.
The Beginning Programmer
November 12, 2010
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.
Jake Collins
November 19, 2010
For checked exceptions you could always use:
http://download.oracle.com/javase/6/docs/api/java/lang/Exception.html
The unchecked list is here:
http://download.oracle.com/javase/6/docs/api/java/lang/RuntimeException.html
Or create your own application specific exceptions where necessary of course.
SoboLAN
April 1, 2011
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.
tshegofatso
May 26, 2011
wat abt the out of memory exception and wat is the IO exception
Hai
May 26, 2011
@ tshegofatso: If you have any specific exception that I missed, I will be glad to add it to the list.
warxsg
August 5, 2011
Useful post !
gcbenison
November 3, 2011
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.
Hai
November 3, 2011
@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.
John Pfeiffer
December 2, 2011
This is a great post, while the official Java docs are comprehensive it’s a pain to drill down.
Jan Tojnar (@jtojnar)
December 28, 2011
Thanks, this is my most visited java related web page.
Lissa
February 16, 2012
Thank you soooo much for this. Exactly what I was looking for!
SoboLAN
March 15, 2012
There is also the IndexOutOfBoundsException: http://docs.oracle.com/javase/7/docs/api/java/lang/IndexOutOfBoundsException.html
Hai
March 18, 2012
@SoboLAN: I added IndexOutOfBoundsException. Thank you.
Gerald F (@gfontejon)
March 22, 2012
InputMismatchException
Hai
March 28, 2012
@gfontejon: Thank you for your input, I added InputMismatchException to the list.
Sourav
April 18, 2012
So much usefull web with java… Thanks the authority to provide to all……………
Matthijs
May 4, 2012
Why don’t you just use the “Direct Known Subclasses” functionality of the Java API for the list of subclasses of the Exception class
http://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html
the RuntimeException class
http://docs.oracle.com/javase/7/docs/api/java/lang/RuntimeException.html
and the IOException class
http://docs.oracle.com/javase/7/docs/api/java/io/IOException.html
instead of tracking them here separately.
Hai
May 4, 2012
@Matthijs: Yes, all of us can do that, but please read my first paragraph of this post for my rationale.
Matthijs
May 4, 2012
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.
Fabricio
May 7, 2012
Excellent!! Thanks!
Chris R
May 26, 2012
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.
Hai
May 29, 2012
@Chris R: `Exception` added. Thank you for reading and comment.
justtherabidrabbit
June 7, 2012
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
Hai
June 7, 2012
@ justtherabidrabbit: What a unique (and rare) exception, but who am I to discriminate; so I added that exception to the list. Thank you.
javacrazzy
June 24, 2012
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
n8chz
July 15, 2012
What about divide by zero?
Hai
July 15, 2012
@n8chz: the Java doc suggests to:
throw new java.lang.ArithmeticException(“divide by zero”);
Java Dev
February 8, 2013
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
Hai
February 9, 2013
@Java Dev: Not all of us use IDE to write Java code.
Thanks
February 15, 2013
This was very useful. Thanks!
m4x
March 12, 2013
Very helpfull. Thanks!