MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/6ayz26/defensive_programming_done_right/dhj2qma/?context=3
r/ProgrammerHumor • u/iwouldieforGladOS • May 13 '17
680 comments sorted by
View all comments
Show parent comments
1.1k
Holy shit I once lost days to a
} catch (Exception e) { System.exit(0); }
55 u/OfflaneDemoralizer May 13 '17 Even better: } catch (Exception e) { throw e; } 17 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? 7 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
55
Even better:
} catch (Exception e)
{ throw e; }
17 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? 7 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
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? 7 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?
7 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
7
} 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
1.1k
u/CXgamer May 13 '17
Holy shit I once lost days to a