Back to home

Example case
Python Exceptions main image

Python Exceptions

The base example is to use a try/except block. You can raise exceptions in code that can be caught by the except block.

1 2 3 4 try: linux_interaction() except: print('Linux function was not executed')

Example case

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class LinkedList: def __init__(self, head=None): self.head = head def getFirst(self): if self.head == None: raise Exception("No items in list") else: return self.head try: ll = LinkedList() ll.getFirst() except Exception, error: print(error)

Dennis O'Keeffe

@dennisokeeffe92
  • Melbourne, Australia

Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
I am currently working on workingoutloud.dev, Den Dribbles and LandPad .

Related articles


1,200+ PEOPLE ALREADY JOINED ❤️️

Get fresh posts + news direct to your inbox.

No spam. We only send you relevant content.