I have a lot of plpgsql functions and I would like to catch the original postgresql error and, based on that value, to throw with a raise or something my custom error.
The section "Trapping Errors" in the plpgsql chapter of the manuals covers this. Does this not do what you want?
-- Richard Huxton Archonet Ltd
---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match