Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception handling - Best practices

vinsiqJan 8 2014 — edited Jan 10 2014

Hi everyone!

I'm studying best pratices in exceptions handling to improve the quality of our code here in the organization, but it's a tricky topic and sometimes I don't know what direction to take,

We use JavaFX.

I'm thinking in always throwing the exceptions from the under methods and catch these exceptions in the controllers classes(the top layer), it's a good pratice?

e.g.

Class LoginController have the login() method.
Inside login(), there are the startSession() method.

startSession() method signature throws Exception1 and Exception2 (both checked exceptions)
login() method signature also throws Exception1 and Exception1

I do like this:

try {

     login();

}

catch (Exception1 | Exception2 ex) {

     throw new RuntimeException("A problem occurred!");

}

It's a good pratice to go in this way?

Thanks!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 7 2014
Added on Jan 8 2014
3 comments
1,039 views