Python Exception Handling

Programming In Python 3 Second Edition page 172
import logging
import warnings
_logger = logging.getLogger(__name__)""" it is custom exception """
class BusinessException(Exception):
it is constructor of custom exception
:param code: code of message exception
:param message: exception message and frontend modal content
def __init__(self, code, message):
self.code = code
self.message = message
def get_message(self):
return self.message
def get_code(self):
return self.code
import logging
import warnings
_logger = logging.getLogger(__name__)
from exception_util.custom_exception import BusinessException
def exception_test(param):
if param == 1:
raise BusinessException("123","custom error exception")
if param == 2:
raise Exception("exception")
def main():
except BusinessException as customErr:
except Exception as customErr:
if __name__ == "__main__":




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

12 Reasons Why You Won’t Want To Miss Update 12

Back up and restore Mongo DB(hosted on AWS EC2) with a shell script, cron, and AWS S3

CI/CD (Pipeline) Clarified

What Is the Application Development Lifecycle?

Creating Collectables in Unity

Why is Python becoming indispensable in IoT Industry?

What is Power BI?

ApeDubai Partners With Bitxmi To Host AMA Session.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
wahyu eko hadi saputro

wahyu eko hadi saputro

i am a reader

More from Medium

[Python] Decorator

Python timeit module

Python logging basicConfig

Python Encapsulation