Page 1 of 1

Old Code, Do I still need to make these checks?

Posted: Tue Oct 12, 2021 12:45 pm
by velocity
Hi! It has been a long time, since I was active here. So I was reading through some old code and I was wondering if these try-catch cases are still necessary to prevent crashes and is this still the "correct" way to do this?


Syntax: Select all

@EntityPreHook(EntityCondition.equals_entity_classname('trigger_multiple'), 'start_touch')
def start_touch_func(args):
try:
obj1 = make_object(BaseEntity, args[0])
except:
return
try:
ob2 = make_object(BaseEntity, args[1])
except:
return
# do more here...

Re: Old Code, Do I still need to make these checks?

Posted: Tue Oct 12, 2021 1:21 pm
by L'In20Cible
velocity wrote:Hi! It has been a long time, since I was active here. So I was reading through some old code and I was wondering if these try-catch cases are still necessary to prevent crashes and is this still the "correct" way to do this?


Syntax: Select all

@EntityPreHook(EntityCondition.equals_entity_classname('trigger_multiple'), 'start_touch')
def start_touch_func(args):
try:
obj1 = make_object(BaseEntity, args[0])
except:
return
try:
ob2 = make_object(BaseEntity, args[1])
except:
return
# do more here...
This never would have prevented a crash. Worst that can happens is a RuntimeError if one of these pointer is not a valid entity. Which effectively have the same result as a return, since the execution stops anyway (minus the exception being logged depending of your logging config). However, chances the game call that function with invalid entities are next to null so I'd say these try block are redundant.

Re: Old Code, Do I still need to make these checks?

Posted: Thu Oct 14, 2021 8:25 am
by velocity
Alright thanks!