Don't look at this title with a despised eye. In fact, "Shit Happens" is a famous saying, and it is still a famous saying. In the Forrest Gump, Aggam stepped on Shit while running, and a frustrated businessman asked him about this, and Akugan expressive said: "Shit happens.", This sentence It means "people who will happen if there will be unsuccessful things, nothing is worthy of strangeness." This businessman then made a slogan of "Shit Happens" and sold. A car that appears in the next curtain with "Shit Happens" slogan, flying into the other car behind him, and it is really "Shit Happens".
"... What is the relationship between this article ???" Don't worry, continue to look down!
Java programmers should be unfamiliar with Exception Handling Mechanism, because Java Language Force programmers must use exception processing to capture the exceptions of non-runtime. So you must have used Try, Catch, Finally keywords, and you are also likely to use this keyword to transfer unprocessed exceptions to the next layer of Call Stack. However, you are likely to have never active New an exception object and then throw it out. You are more likely to have not defined your exception categories.
When using a large system in Java, it is often necessary to define its own exception categories and actively throw out the exceptions at appropriate time. As a result, the program can be more stable.
My habits are:
If this exception belongs to the Runtime nature, and can be remedy, this exception is inherited from java.lang.RuntimeException.
This exception is inherited from java.lang.exception if this exception is not Runtime property and can be remedy.
If this exception cannot be remedy, this exception inherits from Java.lang.Error.
The above three points are completely suggestions for exceptional processing in accordance with the Java language, and I will not explain it. In addition, I also defined an exception category I used, called Shit, which is defined as follows:
Package com.skittles;
Public class shit extends runtimeException {
PRIVATE STRING WhatHAPPENED;
PRIVATE SHIT () {}
Public shit (string whathappened) {
This.whathappened = whathapplened;
}
Public string toString () {
Return whathapplened;
}
}
In the program, for some situations I think absolutely impossible, I will throw out the shit, and the representative program has absolutely should not happen. If this exception occurs, it indicates that there is a strange error inside. In the test program, if Shit Happens, I will find the source and find the error out.
The reason why SHIT inherits from RuntimeException, is because it should not happen, and it can be creating RuntimeException to make the program do not have to go to catch.