It is currently 13 Sep 2025, 16:59
   
Text Size

CardFactories - should they throw?

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

CardFactories - should they throw?

Postby 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?
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?

Postby 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.
User avatar
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?

Postby Max mtg » 28 Aug 2011, 15:40

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
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?

Postby Braids » 28 Aug 2011, 17:55

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}
"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. ;)
User avatar
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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 60 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 60 users online :: 0 registered, 0 hidden and 60 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 60 guests

Login Form