Best Practices for Exception Handling
Subject:   throw new Exception("...")
Date:   2003-11-20 09:46:28
From:   gunjandoshi1
Response to: throw new Exception("...")

When I wrote this article, I was arguing with myself to put the line. I wrote this line with two motives:

1.)I wanted to make a smooth transition to the next line that is:

"Even better, if you think the client code is not going to take any action other than logging if the username is already taken, throw a unchecked exception:
throw new RuntimeException("Username already taken");"

It is difficult for some programmers to think about converting CheckedExceptions to RuntimeExceptions.

2.) I wanted to show that you could achieve the same affect as creating a new Exception class with throwing a plain Exception. However, I do NOT advise people to throw plain Exception classes. My recommendation is to convert the exception into a RuntimeException if the client cannot do anything against it.