ValueError vs IndexError, unpacking arguments with string.split

Morten W. Petersen morphex at gmail.com
Fri Nov 30 08:35:50 EST 2018


Hi there.

I was adding a port specification feature to my surveil project as shown
here:

https://github.com/morphex/surveil/commit/703318f87c4c450a37944b565a10718ef27b57b4

A bit later I was surprised when the script raised an exception, and that I
had to catch a ValueError instead of an IndexError:

https://github.com/morphex/surveil/commit/d5c49c54d4037557aaca1f78178b76441853c7af

I've been reading up on a bit of C++, Assembler etc. lately, so maybe my
mind expected an IndexError because of that, but isn't it logical that the
string is parsed and split, and then later the unpacking operation fails
with an IndexError?

Regards,

Morten

-- 
Videos at https://www.youtube.com/user/TheBlogologue
Twittering at http://twitter.com/blogologue
Blogging at http://blogologue.com
Playing music at https://soundcloud.com/morten-w-petersen
Also playing music and podcasting here:
http://www.mixcloud.com/morten-w-petersen/
On Google+ here https://plus.google.com/107781930037068750156
On Instagram at https://instagram.com/morphexx/


More information about the Python-list mailing list