Skip site navigation (1) Skip section navigation (2)

Re: Can I map "raise XXX" to some custom python exceptions?

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: "W(dot) Matthew Wilson" <matt(at)tplus1(dot)com>
Cc: Dan Halbert <halbert(at)halwitz(dot)org>, psycopg(at)postgresql(dot)org
Subject: Re: Can I map "raise XXX" to some custom python exceptions?
Date: 2011-06-20 14:03:42
Message-ID: BANLkTimDiCYpuk-mO9HphmWEB5ChDcNP8A@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
On Sun, Jun 19, 2011 at 6:45 PM, W. Matthew Wilson <matt(at)tplus1(dot)com> wrote:

> So, really, I want to be able raise specific exceptions within
> postgresql, and then define how those are converted to python objects.

It is an interesting use case. I've recently written a Postgres-based
program where I've used a specific sqlcode for the exceptions. It
would be nice having a mapping errcode->python exception instead of
using a pattern of catching and re-throwing.

However I suspect it wouldn't be a complete solution: still with my
specific example in mind, half of the exceptions are raised from
PL/pgSQL functions or triggers, where I have control over the errcode.
But other errors are generated by database-handled integrity
violations, so I don't see a way to generate an uniform errcode
throughout all the applications.

-- Daniele

In response to

psycopg by date

Next:From: Patrick WongDate: 2011-06-20 16:51:56
Subject: Quick question about install
Previous:From: W. Matthew WilsonDate: 2011-06-19 17:45:24
Subject: Re: Can I map "raise XXX" to some custom python exceptions?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group