Welcome to Dream.In.Code
Become a Java Expert!

Join 149,478 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,608 people online right now. Registration is fast and FREE... Join Now!




Throwing exceptions in Comparator classes?

 
Reply to this topicStart new topic

Throwing exceptions in Comparator classes?

MorningView
19 Apr, 2007 - 04:05 PM
Post #1

New D.I.C Head
*

Joined: 19 Apr, 2007
Posts: 2


My Contributions
Hello everyone,

I have a class 'Player' with a method 'getBattingAverage' for calculating the player's batting average. I would like to use the results of this method in a Comparator but getBattingAverage throws DivideByZeroException. I am unsure of where to proceed from here, my understanding being that it isnt possible to throw exceptions (or deal with methods which throw exceptions) within a Comparator because the Comparator interface doesn't allow for exceptions to be thrown.

If anyone could shed any light on the best course of action that'd be great.

Matt
User is offlineProfile CardPM
+Quote Post

MorningView
RE: Throwing Exceptions In Comparator Classes?
19 Apr, 2007 - 04:56 PM
Post #2

New D.I.C Head
*

Joined: 19 Apr, 2007
Posts: 2


My Contributions
No troubles, I've managed to address the issue. For anyone else who searches through and finds this topic at a later date, I just changed the exception to extend RuntimeException rather than Exception, which seems to work quite nicely.

I can't vouch for it being good form but it serves its purpose.

Cheers.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 03:42PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month