You could create your own Exception class:
public class InvalidSpeedException extends Exception {
public InvalidSpeedException(String message){
super(message);
}
}
In your code:
throw new InvalidSpeedException("TOO HIGH");
Answer from Fortega on Stack OverflowHow can I throw a general exception in Java? - Stack Overflow
java - What is a exception error and how do I fix it? - Stack Overflow
How to trash the exception model in Java: the Either type
Exception in server tick loop. PLEASE HELP!!! [Java] : MinecraftHelp
Videos
You could create your own Exception class:
public class InvalidSpeedException extends Exception {
public InvalidSpeedException(String message){
super(message);
}
}
In your code:
throw new InvalidSpeedException("TOO HIGH");
You could use IllegalArgumentException:
public void speedDown(int decrement)
{
if(speed - decrement < 0){
throw new IllegalArgumentException("Final speed can not be less than zero");
}else{
speed -= decrement;
}
}
What IDE are you using? You should be able to easily solve this error without needing any outside help. On IntelliJ pressing Alt + Enter will give you the option to enclose the encrypt method call in a try/catch block, like such:
try {
MD5Digest.encrypt(entered_password);
} catch (Exception e) {
e.printStackTrace();
}
The method throws an exception, which basically means it can run into an error and the try catch block is a way to handle that error without your program crashing.
The encrypt method is located at the bottom, inside the MD5Digest class. Looking at the first line:
public static void encrypt(String original) throws Exception
It's telling the compiler that it can possibly run into an Exception (error), and that you should be prepared to handle that possibility. Hence the try/catch is required. It will try what's in the try brackets, and then if it runs into an error the code in the catch block will get executed.
Change your main method to this:
public static void main(String []args) throws Exception {.
Since you're calling the encrypt method though the main method, you also need to add the throws Exception to the main method as well. Hope this helps!