Serving the Quantitative Finance Community

 
User avatar
tags
Topic Author
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

on error handling mechanisms

June 15th, 2020, 2:31 pm

(If I remember well it had been discussed in the past, but I was unable to retrieve that thread)

When shall one add error handling mechanisms aka a try/catch/except/raise and when shall one not? (BTW is that programming language-dependent?)

People seem to be binary about it. Either they write some everywhere (and the result is a quite ugly piece of code). Either they would discourage you to even think of it.

Your comments on this much appreciated.

Merci!
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on error handling mechanisms

June 15th, 2020, 3:13 pm

 
User avatar
ISayMoo
Posts: 2332
Joined: September 30th, 2015, 8:30 pm

Re: on error handling mechanisms

June 27th, 2020, 7:43 pm

Go does it well. You can return two values: the actual result and the error code.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on error handling mechanisms

June 28th, 2020, 8:44 am

Go does it well. You can return two values: the actual result and the error code.
Python is also cool in  this regard. e,g, QUADPACK routines. 
I do the same in std::tuple but in Python it's automagic .. it just knows it's a tuple.

Caveat: if you call these functions in a for loop that return tuples it's very bad for performance, so avoid tuple creation/destruction. Example,MC for RNG (Box-Muller returns a tuple) difference of 60 seconds versus 3600 seconds for NT = 500, NSIM = 1'000'000. Was a surprise the first time.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on error handling mechanisms

June 28th, 2020, 8:53 am

Go does it well. You can return two values: the actual result and the error code.
Try it in a BIG loop. 

VBA uses a GLOBAL Err thing. Looking back, it wasn't a bad solution after all :-)

BTW is immutable tuple a language design error?
 
User avatar
ISayMoo
Posts: 2332
Joined: September 30th, 2015, 8:30 pm

Re: on error handling mechanisms

June 28th, 2020, 8:18 pm

No. If you want a mutable sequence, use a list.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on error handling mechanisms

June 29th, 2020, 9:28 am

No. If you want a mutable sequence, use a list.
Well, if list is the answer what's the question again?

- using list as return type??
- tuples can be nested + heterogeneous
- tuples are fixed size
- list are for unbounded homogeneous data

C++ tuples _are_ mutable. C++ treats us as grown-ups.
 
User avatar
ISayMoo
Posts: 2332
Joined: September 30th, 2015, 8:30 pm

Re: on error handling mechanisms

June 29th, 2020, 2:17 pm

const tuples aren't.
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on error handling mechanisms

June 29th, 2020, 6:36 pm

const tuples aren't.
Killjoy. Lockdown.
 
User avatar
tags
Topic Author
Posts: 3162
Joined: February 21st, 2010, 12:58 pm

Re: on error handling mechanisms

June 30th, 2020, 8:15 pm

Thank you for your comments above guys.
So I'm left with the flavor that machinery is a 2nd best.
Maybe recommendations instead would be:
- Write code that works
- Don't allow user interactions
- Something else?
 
User avatar
Cuchulainn
Posts: 20254
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: on error handling mechanisms

July 6th, 2020, 10:06 am

Thank you for your comments above guys.
So I'm left with the flavor that machinery is a 2nd best.
Maybe recommendations instead would be:
- Write code that works
- Don't allow user interactions
- Something else?
Software life is a contract. Things go wrong, even fatal bugs in code.

https://en.wikipedia.org/wiki/Design_by_contract

Image