Python Forum
what exception for a bad function call
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what exception for a bad function call
#1
i am (re-)writing a complex function with many variations of bad ways to call it.  in cases where a bad type is given i raise a TypeError.  for values out of range or just wrong i raise a ValueError.  what should i raise for other bad cases?  i am doing more raising exceptions unless there is a programmatic reason for the caller to simply handle the unusual case, such as providing None to indicate no more of something (the function may need to turn out the lights).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Not knowing what the function does makes it difficult to 'break' it.  Python provides oodles of exceptions/errors Built in Exceptions plus you can create your own custom ones as well User defined exceptions.  Though I would imagine, if your exceptions exceed the actual program, you might be going a bit overboard  Smile
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 796 May-02-2023, 08:40 AM
Last Post: Gribouillis
  create my exception to my function korenron 2 795 Nov-09-2022, 01:50 PM
Last Post: korenron
  TicTacToe Game Add Exception Handling and Warning Function ShaikhShaikh 5 2,429 Nov-03-2021, 05:02 PM
Last Post: deanhystad
  how to call an object in another function in Maya bstout 0 2,086 Apr-05-2021, 07:12 PM
Last Post: bstout
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,506 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,230 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,918 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,250 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,089 Jul-27-2020, 04:19 PM
Last Post: buran
  Python: Call function with variabele? Ending in error. efclem 5 2,959 Apr-22-2020, 02:35 PM
Last Post: buran

Forum Jump:

User Panel Messages

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