Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Asynchronous inputs are at the root of our race problems. -- D. Winker and F. Prosser


devel / comp.lang.python / Re: RuntimeError, or user defined exception

SubjectAuthor
* RuntimeError, or user defined exceptionCecil Westerhof
`- Re: RuntimeError, or user defined exceptionCameron Simpson

1
RuntimeError, or user defined exception

<87sfsygyd6.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16912&group=comp.lang.python#16912

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.lang.python
Subject: RuntimeError, or user defined exception
Date: Fri, 04 Feb 2022 21:39:33 +0100
Organization: Decebal Computing
Lines: 10
Message-ID: <87sfsygyd6.fsf@munus.decebal.nl>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="a547e714002d4858e9adb4037c7287f3";
logging-data="8727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nYR6jCiyjvKJK9Y7gV61Gzh/aKM4Tir8="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:iiQglDW4q9GkxR8xDHGZxDUlDQA=
sha1:AHLRGj1CRVn91i7DcBR55qsI7Ik=
 by: Cecil Westerhof - Fri, 4 Feb 2022 20:39 UTC

I am creating a class that will call a user defined function on user
defined intervals. In my opinion it is an error when the function
takes more as 10% of interval, or more as half a second. What is
better: just using RuntimeError, or creating two exception classes for
this?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: RuntimeError, or user defined exception

<mailman.20.1644037470.7010.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=16920&group=comp.lang.python#16920

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: RuntimeError, or user defined exception
Date: Sat, 5 Feb 2022 16:04:24 +1100
Lines: 48
Message-ID: <mailman.20.1644037470.7010.python-list@python.org>
References: <87sfsygyd6.fsf@munus.decebal.nl>
<Yf4FWD0bFGvhNm50@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de pXRKN2uCq8Ia5rUNn/ylWwTQOf5DOdY8ZroOH22SYm+Q==
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'failures':
0.07; "'''": 0.09; 'else:': 0.09; 'rejected': 0.09; 'situations':
0.09; 'supplied': 0.09; 'cheers,': 0.11; 'builtin': 0.16;
'cameron': 0.16; 'from:addr:cs': 0.16; 'from:addr:cskk.id.au':
0.16; 'from:name:cameron simpson': 0.16; 'iirc,': 0.16;
'interpreter': 0.16; 'message-id:@cskk.homeip.net': 0.16;
'occur.': 0.16; 'option.': 0.16; 'received:13.237': 0.16;
'received:13.237.201': 0.16; 'received:13.237.201.189': 0.16;
'received:cskk.id.au': 0.16; 'received:id.au': 0.16;
'received:mail.cskk.id.au': 0.16; 'reuse': 0.16; 'simpson': 0.16;
'wrote:': 0.16; 'code.': 0.17; 'bug': 0.19; 'calls': 0.19;
'to:addr:python-list': 0.20; 'exception': 0.22; 'skip:_ 10': 0.22;
'code': 0.23; 'command': 0.23; "i'd": 0.24; 'anything': 0.25;
'actual': 0.25; 'classes': 0.26; 'creating': 0.27; 'else': 0.27;
'function': 0.27; 'expect': 0.28; 'purpose': 0.28; 'error': 0.29;
'header:User-Agent:1': 0.30; 'raise': 0.31; 'half': 0.32; 'here,':
0.32; "wouldn't": 0.32; 'core': 0.34; 'header:In-Reply-To:1':
0.34; 'received:au': 0.35; 'runs': 0.35; 'main': 0.37; 'using':
0.37; 'class': 0.37; 'could': 0.38; 'two': 0.39; 'valid': 0.39;
'use': 0.39; '(with': 0.39; 'seeing': 0.39; 'situation': 0.40;
'try': 0.40; 'should': 0.40; 'method': 0.61; 'internal': 0.63;
'skip:o 20': 0.63; 'between': 0.63; 'skip:b 10': 0.63; 'skip:r
20': 0.64; 'opinion': 0.64; 'received:13': 0.64; 'your': 0.64;
'tool': 0.65; 'received:userid': 0.66; 'outside': 0.67; 'reach':
0.69; 'raised': 0.70; 'skip:f 20': 0.75; '10%': 0.76; '(other':
0.84; 'catch': 0.84; 'indicates': 0.84; 'narrow': 0.84; 'val':
0.84; 'opt': 0.89
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <87sfsygyd6.fsf@munus.decebal.nl>
User-Agent: Mutt/2.1.5 (2021-12-30)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <Yf4FWD0bFGvhNm50@cskk.homeip.net>
X-Mailman-Original-References: <87sfsygyd6.fsf@munus.decebal.nl>
 by: Cameron Simpson - Sat, 5 Feb 2022 05:04 UTC

On 04Feb2022 21:39, Cecil Westerhof <Cecil@decebal.nl> wrote:
>I am creating a class that will call a user defined function on user
>defined intervals. In my opinion it is an error when the function
>takes more as 10% of interval, or more as half a second. What is
>better: just using RuntimeError, or creating two exception classes for
>this?

You could reuse TimeoutError, a builtin exception raised by OS calls
which time out: https://docs.python.org/3/library/exceptions.html#TimeoutError

I wouldn't use RuntimeError. Its core purpose is interpreter failures
IIRC, and I use it myself for situations which should never occur -
things indicating an actual bug in my code.

Specificly, I do not expect to try to catch RuntimeError, and broadly
don't expect anything else too either (with some narrow exceptions).
Whereas you would very reasonably catch TimeoutError as a situation
which can readily occur. _Particularly_ with a tool which runs code
supplied from outside - it _might_ do anything.

IMO your situation is a misbehaviour, not an internal bug. I'd reach for
TimeoutError.

An example from my own code where I use a RuntimeError:

class FSTagsCommand(BaseCommand, TagsCommandMixin):
''' `fstags` main command line utility.
'''
GETOPT_SPEC = 'o:'
[.......]
def apply_opt(self, opt, val):
''' Apply command line option.
'''
options = self.options
if opt == '-o':
options.ontology_path = val
else:
raise RuntimeError("unhandled option")

Here, the BaseCommand superclass parses command line options according
to GETOPT_SPEC. The apply_opt() method gets called with any valid
options. GETOPT_SPEC='o:', so seeing anything except '-o' in apply_opt()
indicates a mismatch between GETOPT_SPEC and my apply_opt implementation
(other options get rejected by BaseCommand). So _if_ my code gets there,
that is an internal bug of my own.

Cheers,
Cameron Simpson <cs@cskk.id.au>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor