They are both doing two catches.
The divide catches gives a more direct output error than you would get with the second catch offered with less code.
i.e for Divide
If you get a NoSuchElement error, it'll strictly go into that catch and print out that direct error (but you should probably print 'e' in your throw as well)
If you get a ArithmeticFunction error, itl'l strictly deal with arithmetic.
i.e for second:
If it gets either exception, it'll toss it to e. In this case, you could print a general throw, such as "no suitable input" and it would handle both types of exceptions, but it is less versatile.
You can make it do the same thing as the divide fx by creating an if statement for checking the instance type (NoSuch or Arithmetic), but at that point you should really just go back to using the catch offered in divide.
I wrote up a quick mock-up to help comprehend, it's in Python but you should get the gist.
Code
foo = None
bar = 0
try:
a = foo//0
except TypeError as e:
print("foo is wrong variable type!\nERROR: ", str(e))
try:
b = (bar // 0)
except ZeroDivisionError as e:
print("Cant divide by 0!\nERROR: ", str(e))
try:
a = foo//0
b = (bar // 0)
except TypeError or ZeroDivisionError as e:
print("ERROR!")
print("ERROR IS ZERODIVISION?: ", isinstance(e, ZeroDivisionError))
print("ERROR IS TYPEERROR?: ", isinstance(e, TypeError))
Logs:
Code
foo is wrong variable type!
ERROR: unsupported operand type(s) for //: 'NoneType' and 'int'
Cant divide by 0!
ERROR: integer division or modulo by zero
ERROR!
ERROR IS ZERODIVISION?: False
ERROR IS TYPEERROR?: True
This post was edited by Candyzcanes on Oct 18 2019 11:00pm