简体   繁体   中英

Naming convention for checked and unchecked exceptions in Java

I am writing an application wehre I have some custom exception classes. The naming convention what I use for the custom exception classes is <error-name>Error.java .

For example:

  • AccessDeniedError.java
  • InvalidMediaTypeError.java
  • EmptyRequestBodyError.java
  • ...

Some of my custom exception classes extends Exception , they are checked exceptions. The rest of my custom exceptions are unchecked (extends RuntimeException ).

My naming convention does not reflect that so when someone only see the name of the exception then he is not able to decide whether it is a checked or unchecked exception.

I am not sure if the class name needs to reflect the type of the exception or not, but the naming I use does not tells anything about it.

I would like to keep the classnames as short as possible so I DO NOT want to use names like AccessDeniedCheckedException or AccessDeniedUncheckedException . These names are too long for me.

I tried to google for it but I have not found any usefull in this topic.

Can I continue using this naming or better to rename my custom exception classes in order to they show the type of the exception as well?

You should not name them checked or unchecked , unless there are two types of these; just like IOException and UncheckedIOException for example.

Otherwise users will know what types these are with the help of the compiler, obviously.

About the length of the class name, well, JDK itself has some names that will scare you; or look into spring - those are some heavy long names.

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