The Right Approach to Exceptions

Jonathan M Davis jmdavisProg at
Sat Feb 18 17:33:37 PST 2012

On Saturday, February 18, 2012 23:26:35 Jose Armando Garcia wrote:
> I think that is a good compromise. The one thing we need to solve is
> that for example Oracle's error code may collide with POSIX error
> code. This is why I suggested using namespace but there may be other
> solutions.

What relation would POSIX and Oracle codes have though? I'd expect them to be 
on completely different exception types. POSIX error codes would make sense on 
something like FileException, whereas Oracle codes would make sense on 
something like DatabaseException or OracleException. The problem you run into 
is when you also have PostgresException and SQLLiteException which derive from 
DatabaseException. You could have an error code in it, but it wouldn't 
necessarily mean much if it weren't tied to the specific database exception 
type. The hierarchy that can be ignored is when OracleException or 
PostgresException have derived types based on the error code (which then 
hopefully provide additional information beyond just the error code).

But you still end up with a minimal exception hierarchy that everyone has to 
use if they want to stick to error codes. People can use FileException and its 
error code rather than FileNotFoundException and NotFileException, but they'd 
still have to use FileException rather than Exception to get the error code.

- Jonathan M Davis

More information about the Digitalmars-d mailing list