0

This is my code snippet of trying to create a custom exception class which takes a input parameter about the exception

class Error(Exception):
    pass
mssg = "None"

class timepasserror(mssg ,Error):

    print(f"the error is {mssg}")
    

and I am planning to use it as mentioned below

if 1==1:#some conditon
    raise timepasserror('something')

I am getting this error :

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

I am not sure if its possible to do so . If yes can anyone guide me Thanks

Kaiser
  • 187
  • 8

1 Answers1

0

You are having an error because you are trying something that does not make sense, trying to inherit from a string instance (mssg = "None") - this will never work.

Otherwise one will see this error (when trying to do things correctly) when trying to inherit from two classes which have differing metaclasses, and this question have been asked around plenty of times: the solution would be creating a base metaclass that inherits from both conflicting metaclasses - Abstract class inheriting from ABC and QMainWindow

In your case, please, take a step back and find out how to implement the behavior you want in your custom exception: it won't take multiple inheritance.

jsbueno
  • 99,910
  • 10
  • 151
  • 209