Q:

How to raise own error when one argument is missing?

Hi I'm pretty new to Python and I've just started to learn about errors and exceptions.I have this function in a class that inserts a line at a given index called num.I know python will raise an error if no num is given but I want to raise my own error.How do I do that?This is what I tried. But the error raised is still the default error?
 def insertNum(self, num, line):
    if num== None:
        raise Exception("Num not specified.")
    else:
        self.list.insert(num, line)
    return self.list

A:

You can use try...except statement.
def insertNum(num, line):
   try:
     list.insert(num, line)
     return list
   except:
     print('custom error')

