Page 1 of 1

CardFactories - should they throw?

PostPosted: 28 Aug 2011, 12:54
by Max mtg
LazyCardFactory sometimes is asked for cards it cannot load.
Why is default factory's behaviour to throw?

Maybe it should return null, and let the invoking code decide that to do about that?

Re: CardFactories - should they throw?

PostPosted: 28 Aug 2011, 15:20
by Rob Cashwalker
What cards could it possibly not be able to load? Your mtg-data cards?

Re: CardFactories - should they throw?

PostPosted: 28 Aug 2011, 15:40
by Max mtg
Rob Cashwalker wrote:What cards could it possibly not be able to load? Your mtg-data cards?
Why just my mtg-data cards? :)
Imagine you downloaded a deck, forge wants to check if all cards are supported. LazyCardFactory does not know which cards are, and can not check by searching in precached ones.

But this is unrelated to my original question abouth throwing exceptions

Re: CardFactories - should they throw?

PostPosted: 28 Aug 2011, 17:55
by Braids
Max mtg wrote:
Rob Cashwalker wrote:What cards could it possibly not be able to load? Your mtg-data cards?
Why just my mtg-data cards? :)
Imagine you downloaded a deck, forge wants to check if all cards are supported. LazyCardFactory does not know which cards are, and can not check by searching in precached ones.

But this is unrelated to my original question abouth throwing exceptions
my current thinking is to throw a new checked exception, so the UI could figure out how to tell the user. the checked exception forces the caller to deal with the problem. but returning null just means we'll get NullPointerExceptions when we don't expect them.

see also issue 29 {Handle getCard() invalid card name more gracefully}