[Tutor] Inherit from SyntaxError?

Alan Gauld alan.gauld at yahoo.co.uk
Sun Mar 19 10:48:56 EDT 2023


On 19/03/2023 09:30, Albert-Jan Roskam wrote:

>    MemoryError), I've always regarded SyntaxError as "special". Are there any
>    disadvantages to inheriting from SyntaxError? I could also inherit from
>    ValueError.

I believe it should work OK but I also believe (possibly wrongly!)
that SyntaxError is only ever thrown by the compiler prior to
commencing execution of the code, so you would never normally
be catching it and making inheritance of dubious value. But if
it truly is intended to indicate a syntax error in your parsed
data then I don't think inheriting from SyntaxError will cause
any particular problems.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Tutor mailing list