Exception Handling on methods C# -
Exception Handling on methods C# -
let's suppose have next code...
try { await task.run(() => autobuyandsell.discard_players(client, this)); if (stop == false) { await task.run(() => autobuyandsell.buy_300_players(client, this)); } } grab (expiredsessionexception ex) { relogin = true; b_stop.performclick(); }
inside autobuyandsell expiredsessionexception can occur phone call methods can throw exception. question is, need add together try/catch block within function or it's plenty handle extern exception?
answer accepted:
as need of programme exit method , restart variables, eventually, decided utilize try/catch outside method.
you grab them have won't "know" if/how much of discard_players
or buy_300_players
code executed, , @ point exception occurred, etc. may bad idea.
for illustration if these methods persist state disk/database wont "know" if happened or not.
(i maintain using quotes on "know" because guess possible interrogate phone call stack etc when catching exception find out raised in order find these things out that's going messy pretty quickly!)
if grab them within methods can command how handled (perhaps undoing info have persisted before throwing 1 time again can start afresh, example) much better.
so depending on functionality of these 2 functions should decide approach works best application
c# exception try-catch
Comments
Post a Comment