Recent

Author Topic: 'try' best practice?  (Read 1094 times)

MoCityMM

  • Jr. Member
  • **
  • Posts: 72
'try' best practice?
« on: March 23, 2020, 02:52:06 pm »
Was wondering if 'try..finally' and 'try..exception' is a necessary conjunction in code or one without the other is really all that is needed?

What is your coding practice with the two?


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12642
  • FPC developer.
Re: 'try' best practice?
« Reply #1 on: March 23, 2020, 03:24:20 pm »
Was wondering if 'try..finally' and 'try..exception' is a necessary conjunction in code or one without the other is really all that is needed?

What is your coding practice with the two?

It really depends on your application field. In my current situation doing machine vision, most exceptions will kill the application anyway, and there is little to none dynamic allocation per item/transaction, so there is not much point in doing so.

In previous jobs I did webdevelopment, and then it is absolutely required to make sure an aborted request releases all its memory.

ASerge

  • Hero Member
  • *****
  • Posts: 2475
Re: 'try' best practice?
« Reply #2 on: March 23, 2020, 08:55:31 pm »
Was wondering if 'try..finally' and 'try..exception' is a necessary conjunction in code or one without the other is really all that is needed?
What is your coding practice with the two?
The "try finally" construction is often used. Without it, the code even looks like a novice's. The "try except" construction is much less common, only if need to handle some exception. And by the way, these are completely different constructions in meaning, which is why I don't like the fact that they are united in some languages. They only have "try" in common.

440bx

  • Hero Member
  • *****
  • Posts: 6074
Re: 'try' best practice?
« Reply #3 on: March 23, 2020, 10:31:27 pm »
What is your coding practice with the two?
I use "try/except" only when the code I'm writing is "messing" with things that don't belong to - are not managed by - my program.

I never use "try/finally".  My viewpoint on that one is, if the program is structured correctly, there will never be a need for it.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018