Menu
LogoLogoRight From BasicsInterview PrepCoding Questions
Articles
  • Hosting
  • Golang
  • Python
BlogBooks
SubscribeBuy me a Coffee!
🌜
🌞
LogoLogoRight From Basics
  • Interview Prep
  • Coding Questions
  • Articles
    • Hosting
    • Golang
    • Python
  • Blog
  • Books
  • Subscribe
  • Buy me a Coffee!
  • General Ideas & Concepts
    • Computing Terminologies
    • Programming Concepts
    • Types of Data Structures
  • Python Basics, Libraries & Concepts
    • Operators
    • Lists & Tuples
    • Dictionaries
    • Sets
    • Strings & Characters
    • Functions
    • Control Structures
    • Range Operator
    • Iterators & Generators
    • Priority Queues
    • Exception Handling
    • Object-Oriented Programming
    • Inheritance
    • References
    • Enums
    • Random Numbers
    • Input & Output
    • Miscellaneous Methods and Techniques
  • Sorting
    • Preliminaries
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
    • Merge Sort
    • Quick Sort
  • Searching
    • Binary Search

Exception Handling

Try-Except Block#

try:
doSmth()
except:
print("Error!")

Raising Exceptions#

if x > 0:
raise RuntimeError("Input cannot be greater than zero.")
else:
doSmth();

Creating Your Own Exceptions#

class ValueTooLargeError(Error):
"""Raised when the input value is too large"""
pass
# Main Program
if x > 0:
raise ValueTooLargeError
Previous
« Priority Queues
Next
Object-Oriented Programming »
  • Try-Except Block
  • Raising Exceptions
  • Creating Your Own Exceptions

Links

  • Home
  • Medium Publication
  • Harish V
Copyright © 2021 Right From Basics. Built with Docusaurus.