Python Forum
Error handling using cmd module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error handling using cmd module
#1
I'm using Python's cmd module to write my own command line interpreter. I'm not sure how to handle errors using the modules.

Let's say my command eat requires 1 argument.

The function usually goes as follows:

    def do_eat(self, arg):
        args = arg.split()
        if len(args) < 1:
            print("Missing arguments!")
            return
However, I was wondering if one could write it as:

    def do_eat(self, arg):
        args = arg.split()
        if len(args) < 1:
            raise "Missing arguments" # Or raise an enum
Reply


Messages In This Thread
Error handling using cmd module - by leifeng - Jun-04-2020, 05:48 AM
RE: Error handling using cmd module - by DeaD_EyE - Jun-04-2020, 07:47 AM
RE: Error handling using cmd module - by leifeng - Jun-06-2020, 06:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculating Average with Error Handling mikasa 7 462 May-07-2024, 07:48 AM
Last Post: snippsat
Star python exception handling handling .... with traceback mg24 3 1,321 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Help needed with a "for loop" + error handling tamiri 2 2,606 May-27-2022, 12:21 PM
Last Post: tamiri
  Handling Python Fatal Error richajain1785 7 6,020 Oct-14-2021, 01:34 PM
Last Post: Tails86
  Error Handling JarredAwesome 5 3,002 Oct-17-2020, 12:41 AM
Last Post: JarredAwesome
  Excpetion Handling Getting Error Number gw1500se 4 2,447 May-29-2020, 03:07 PM
Last Post: gw1500se
  vlc module error pythonprogrammer 1 2,905 Apr-23-2020, 04:16 AM
Last Post: Larz60+
  Handling exception from a module dchi2 11 5,709 Nov-25-2019, 08:47 AM
Last Post: dchi2
  Warning / Error handling in python Prarthana_12 1 5,147 Feb-08-2019, 09:21 PM
Last Post: snippsat
  Help With Error Handling jo15765 6 4,163 Sep-14-2018, 06:27 PM
Last Post: jo15765

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020