“This is the 10th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.

The vast sea of millions, thank you for this second you see here. I hope my article is helpful to you!

May you keep your love and go to the mountains and seas in the coming days!

Note: yesterday we learned about the abnormal system part of what? But it’s a pretty big system, so let’s take a look.

😄 Abnormal large system

  • Exception architecture:

📬 Exception

Exception is another very important Exception subclass. Exceptions that can be caught and handled by the program itself. When such exceptions occur, we need to correct the code and fix the program. Exceptions fall into two categories: runtime and compile-time.

🔎 2.3.1Runtime exception

  • Definition: a RuntimeException class and its subclasses abnormalities, such as NullPointerException (null pointer exception), IndexOutOfBoundsException (subscript cross-border exception), said the JVM exceptions that may occur during operation.

  • Features: This type of exception is not checked by the Java compiler. It is usually caused by a program logic error. Such programs should logically avoid such exceptions as far as possible. When such an exception may occur in a program, it will be compiled even if it is not caught by a try-catch statement or thrown without a throws clause declaration. You can choose to capture processing in your program or not. If a runtime exception is generated, you need to modify the code to avoid it. For example, if a divisor of zero occurs, you need to code to avoid it!

  • Note: RuntimeException is automatically thrown and caught by the JVM (even if we didn’t write an exception catch statement at runtime!!). In most cases, the occurrence of such exceptions is a problem with the code itself, which should be solved logically and improved.

    So let’s take a look at what runtime exceptions look like, and what I want to say is, if you get an exception, don’t be nervous, just copy the simple class name of the exception into the API and look it up. And see what the abnormality is.

    As you can see, our program logic is faulty, so we have an arithmetic exception. We can just change int b to be equal to 10, or b not equal to 0.

    So we don’t have to worry about exceptions. You can start by looking at the name of the exception class, see what the exception is, see what the reason is, find out where our program went wrong and modify it to run normally.

  • So we didn’t handle anything, so when we get an exception, who handled the exception?

    Is the JVM’s default: the name, cause, location, etc., of the exception is printed to the console, but the program cannot continue to execute.

🔎2.3.2 Non-runtime Exceptions (Compile time exception)

  • Definition: Exception except for RuntimeException and its subclasses.

  • Features: This type of exception is checked by the Java compiler. If such an exception occurs in a program, it is an exception that must be handled from a program syntax perspective. For example, ClassNotFoundException (the specified class exception was not found) and IOException (the IO stream exception), which cannot pass compilation unless they are declared to throw or try-catch.

  • Note: In our programs, we usually do not customize the exception class, but use the exception class provided by the system. The exception must be handled manually by adding a catch statement to the code.

    As you can see from the comments, the createNewFile() method handles IOException, which in turn inherits from Exception and is a non-runtime Exception, so must handle exceptions.

    So if we have a compile-time exception, we will get an error at compile time, and we must handle this exception, otherwise the program will not compile.

🌸 summary

I believe that you have an in-depth understanding of the abnormal system, then we continue to look forward to the next chapter of the abnormal more content! Welcome to the next chapter!

Let’s refuel together, too! I am not just, if there is any missing, wrong place, also welcome you to criticize in the comments of talent leaders! Of course, if this article is sure to help you a little, please kindly and lovely talent leaders to give a thumb-up, favorites, one key three even, thank you very much!

Here, the world is closed for today, good night! Although this article is over, I am still here, never finished. I will try to keep writing articles. The coming days are long, why fear the car yao ma slow!

Thank you all for seeing this! May you live up to your youth and have no regrets!

\