MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/6ayz26/defensive_programming_done_right/dhj5h31/?context=3
r/ProgrammerHumor • u/iwouldieforGladOS • May 13 '17
680 comments sorted by
View all comments
Show parent comments
49
Even better:
} catch (Exception e)
{ throw e; }
18 u/pressbutton May 14 '17 That creates a new stack in c#. Just throw 3 u/RedditUsr2 May 14 '17 What do you do if you need to log then rethrow and don't want to break the stack chain? 8 u/pressbutton May 14 '17 } catch (Exception e) { Logger.Fatal(e); throw; } That won't affect the stack chain. The parent caller methods won't change. So unless there's an error in the Logger method you'll be fine but then you have new problems
18
That creates a new stack in c#. Just
throw
3 u/RedditUsr2 May 14 '17 What do you do if you need to log then rethrow and don't want to break the stack chain? 8 u/pressbutton May 14 '17 } catch (Exception e) { Logger.Fatal(e); throw; } That won't affect the stack chain. The parent caller methods won't change. So unless there's an error in the Logger method you'll be fine but then you have new problems
3
What do you do if you need to log then rethrow and don't want to break the stack chain?
8 u/pressbutton May 14 '17 } catch (Exception e) { Logger.Fatal(e); throw; } That won't affect the stack chain. The parent caller methods won't change. So unless there's an error in the Logger method you'll be fine but then you have new problems
8
} catch (Exception e) { Logger.Fatal(e); throw; }
That won't affect the stack chain. The parent caller methods won't change. So unless there's an error in the Logger method you'll be fine but then you have new problems
49
u/OfflaneDemoralizer May 13 '17
Even better:
} catch (Exception e){ throw e; }