In C++ I can declare a function which can not further throw exceptions as under
int myfunction (int param) throw(); // no exceptions allowed
Can I have such declaration in Java programming language?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, any method can always throw an unchecked exception (
RuntimeExceptionandError).You only need to list checked exceptions (
Exceptionsubclasses that don’t derive fromRuntimeException) in the method declaration.And an ugly side-note: while the compiler does check that no checked exception is thrown that is not declared, you can work around that with some ugly tricks (that’s sometimes called a sneaky throw, Project Lombok supports it explicitly).