CardFactories - should they throw?
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
4 posts
• Page 1 of 1
CardFactories - should they throw?
by Max mtg » 28 Aug 2011, 12:54
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?
Why is default factory's behaviour to throw?
Maybe it should return null, and let the invoking code decide that to do about that?
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: CardFactories - should they throw?
by Rob Cashwalker » 28 Aug 2011, 15:20
What cards could it possibly not be able to load? Your mtg-data cards?
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: CardFactories - should they throw?
by Max mtg » 28 Aug 2011, 15:40
Why just my mtg-data cards?Rob Cashwalker wrote:What cards could it possibly not be able to load? Your 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
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: CardFactories - should they throw?
by Braids » 28 Aug 2011, 17:55
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.Max mtg wrote:Why just my mtg-data cards?Rob Cashwalker wrote:What cards could it possibly not be able to load? Your 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
see also issue 29 {Handle getCard() invalid card name more gracefully}
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. 

-
Braids - Programmer
- Posts: 556
- Joined: 22 Jun 2011, 00:39
- Location: Unknown. Hobby: Driving myself and others to constructive madness.
- Has thanked: 1 time
- Been thanked: 1 time
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 60 guests