main should throw an exception more specific than Exception
10 public static ArrayList<PrintWriter> noslist = new ArrayList<>();
11 public static ArrayList<User> Userdb = new ArrayList<User>();
12
13 public static void main(String[] args) throws Exception {14 System.out.println("Server signing On");
15 ServerSocket ss = new ServerSocket(9085);
16 MessageDispatcher md = new MessageDispatcher();
main should throw an exception more specific than Exception
5import java.net.*;
6
7public class Client {
8 public static void main(String[] args) throws Exception { 9 System.out.println("Client Signing on");
10 try {
11 Socket soc = new Socket("127.0.0.1", 9085);
Description
throws
clauses should not contain generic exception types such as Throwable
, Exception
, or RuntimeException
.
Instead, extend RuntimeException
and create more specific exception types which are relevant to your use case.
This issue will be reported for method and constructor declarations with throws
clauses that contain any of the following exception types:
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
Bad Practice
Avoid using overly generic exception types:
public float getPercent() throws RuntimeException { ... }
Recommended
Use a more specific exception type instead.
class CalculationException extends RuntimeException {
// ...
}
// ...
public float getPercent() throws CalculationException { ... }