How to make our exception handling flexible enough-we can create an exception class ourselves (common operations for all exceptions)
In the user management system, the specific operation is as follows:
1. Create a Userexception class
2, find superclass, click Browse, select Java.lang.Exception, complete the creation
3, open Userexception.java, you can see Userexception inheritance and exception (here you can change excetion to runtimeexception)
4, next cover the parent class construction method, right click, find souce in the Generate constructors Frome superclass
Specific examples are as follows: (Exception handling for list user management system and map user management system)
1. List User Management system
User. Java
Userexception.java
Userhandllerbylist.java
Test code and output results
2. Map User Management System
User.java
Userexception
Userhandlerbymap.java
Test code and output results
Summary: In Java, you create an exception class to handle the user management system method, relative to the C language, the code amount is greatly reduced, and the code structure is clear, it is easy to understand, in addition to modify the exception information, more convenient!
In the test, if you add multiple users at the same time, you will find that as long as a user error, no other users can continue to add, so I test with only one user to do the operation, which is also in line with the user's registration, the user is a one to register, not a pile of registration together.
Special exception Handling in Java--application of exception handling in user management system (very important)