简体   繁体   中英

What is the most Pythonic way to raise an exception related to an unexpected file type?

Quick question. I am trying to write reusable code, and haven't found too many other instances of it coming up. Say a script is looking for an XML file, I could just raise a generic RuntimeException, but I am not sure if it would be informative for others using my code, or even the type of thing they would be likely to catch in an except statement. Any thoughts?

You can make your own exception by extending the base Exception class.

See: https://docs.python.org/2/tutorial/errors.html#user-defined-exceptions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM