SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
tagoma
Topic Author
Posts: 18363
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: 62637
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: on error handling mechanisms

June 15th, 2020, 3:13 pm

Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
ISayMoo
Posts: 2340
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: 62637
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

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.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
Cuchulainn
Posts: 62637
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

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?
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
ISayMoo
Posts: 2340
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: 62637
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

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.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
ISayMoo
Posts: 2340
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: 62637
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: on error handling mechanisms

June 29th, 2020, 6:36 pm

const tuples aren't.
Killjoy. Lockdown.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
tagoma
Topic Author
Posts: 18363
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: 62637
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

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
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On