Course contentsShow
← Java
Lesson 818 of 2,87019. Exception Hierarchy and Custom ExceptionsFree lesson

Exception Naming Conventions

Follow Java naming conventions: suffix with Exception, use descriptive names, and maintain consistency.

Exception Naming Conventions

What you'll learn: How to name your custom exceptions so they're instantly recognizable and follow Java's established patterns.

When you create custom exceptions, naming them correctly makes your code professional and immediately understandable. Java has clear conventions that signal "this is an exception type" to anyone reading your code.

The Core Rules

Always Suffix with "Exception"

Every custom exception class name should end with the word Exception. This makes the type's purpose crystal clear at a glance.

// Good examples
public class InvalidAccountException extends Exception { }
public class PaymentProcessingException extends Exception { }
public class DataFormatException extends RuntimeException { }

// Bad examples (don't do this)
public class InvalidAccount extends Exception { }  // Missing suffix
public class PaymentError extends Exception { }    // Wrong suffix

Use Descriptive, Specific Names

The name before "Exception" should clearly describe what went wrong. Think of it like labeling boxes in a warehouse—be specific enough that someone knows exactly what's inside.

// Descriptive
public class InsufficientFundsException extends RuntimeException { }
public class EmailAlreadyRegisteredException extends RuntimeException { }

// Too vague
public class ProblemException extends Exception { }
public class BadDataException extends Exception { }

Maintain Consistency Within Your Project

If you name one exception UserNotFoundException, don't name another ProductNotFoundError. Stick to a pattern throughout your application. All similar situations should follow the same naming structure.

The Analogy

Think of exception names like emergency signs in a building: "Fire Exit," "Emergency Stop," "First Aid." They're instantly recognizable because they follow conventions. If someone labeled one "Burning Building Escape Route," it would work but break the pattern everyone expects.

Key Takeaway: Always suffix custom exceptions with Exception, use descriptive names that clearly indicate the problem, and maintain consistent naming patterns across your entire codebase.