We solve problems

  • Count on us to deliver high quality tailor-made software
  • We provide training on TDD, clean code, refactoring and JavaScript
  • We are committed consultants
  • We help teams deliver value

Catch the exception and throw it again

Same behavior in Python and C#...
Wrong code:

  1.  
  2. try:
  3. # some code
  4. except Exception, e:
  5. # log the exception or whatever
  6. raise e
  7.  

Right code:

  1.  
  2. try:
  3. # some code
  4. except Exception, e:
  5. # log the exception or whatever
  6. raise # JUST RAISE!!!
  7.  

Wrong code:

  1.  
  2. try
  3. {
  4. // whatever
  5. }
  6. catch (Exception e)
  7. {
  8. // log the exception or whatever
  9. throw e
  10. }
  11.  

Right:

  1.  
  2. try
  3. {
  4. // whatever
  5. }
  6. catch (Exception e)
  7. {
  8. // log the exception or whatever
  9. throw // JUST THROW!!!
  10. }
  11.  

Reason: Exception stacktrace is lost if you write "raise e" or "throw e" instead of just "raise" or "throw".

Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.
  • http://bloguay.com/cheapuggs215/2011/12/15/uggs-nevertheless/ uggs

    i have got both DTS and Dolby Surround home theather system at home and the sound is superb