db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

Product News from the Core Team

This blog features product news right from the core developer team, once new features and functions get checked into Subversion, available as Continuous Build every 2 hours.

Get Ready to Catch

db4o 6.2 introduces some dramatic changes to how exceptions are handled within the db4o core. db4o was initially designed to "always work" no matter what was thrown at it and therefore it did not throw many exceptions. This has proven to be nice in some cases and problematic in others. In particular when a user would like to know what went wrong so it can be handled in different ways. For instance, if an object can't be saved properly, the user could try changing the object and re-saving. Another common use case is to display a message on a GUI letting the GUI user know what happened. Prior to version 6.2, users did not have to design with db4o exceptions in mind, but starting from 6.2 and beyond, db4o will now throw Runtime/Unchecked Exceptions.

This is a great step forward in terms of usability for db4o providing immediate feedback of problems and enabling new features such as Unique Constraints (also included in v6.2). Unique Constraints allow you to specify that a particular field must be unique across all instances of a Class. The reason this feature can now be implemented is because db4o can now throw a Unique Constraint Exception that will show exactly what constraint was violated along with the violating object and value.

How will this effect you?

First of all, version 6.2 is a development version so you should not use it in a production environment; use the stable 6.1 release for production. If you are in the early stages of development, it would be a good idea to start using 6.2+ so you will not have any upgrade problems later on.

When upgrading from a previous version of db4o to 6.2+, you should do thorough testing of your application so you can make sure you're catching these new exceptions and handling them appropriately. In particular, you should catch exceptions thrown by ObjectContainer.commit().

try {
   
    // do stuff

    oc.commit();
}
catch (RuntimeException e) {
    oc.rollback();
    throw e; // or display error message
}
 

If you want to catch all exceptions from db4o, you can catch Db4oException. All exceptions thrown from db4o will will be subclasses of Db4oException.

Another important change to be aware of is that all fatal errors will throw directly out of db4o, for instance OutOfMemory Errors.

The exception handling effort is an ongoing task and and you can watch the progress on this JIRA ticket.

Published Monday, March 19, 2007 7:02 AM by treeder


Comments

 

ijuma said:

Shouldn't clients catch Db4oException? The idea behind having a superclass in the exception hierarchy is to allow clients to catch that instead of RuntimeException...

March 19, 2007 12:05 PM
 

gustav3d said:

'pardon me,  but  is this for real ?

youre using RuntimeExceptions ??

how can a team of 'skilled' people come up with an idea like that ?

March 19, 2007 4:15 PM
 

treeder said:

"Shouldn't clients catch Db4oException? The idea behind having a superclass in the exception hierarchy is to allow clients to catch that instead of RuntimeException..."

This is at your discretion. But ask yourself whether you would change the behaviour for a different exception in your code.

March 19, 2007 6:29 PM
 

ErikNRC said:

Unique Constraints, this sounds sweet. Looking forward to try that out.

March 19, 2007 11:42 PM
 

db4o Newsletter said:

Welcome to the April newsletter! Version 6.1 Stable and Ready for Shipment 6.2 Dev with Unique Constraints,

March 22, 2007 2:33 AM
 

db4o in Chinese said:

事件 2nd Global db4o User Conference 2007 (dUC) July, 9 and 10 - Fort Mason - San Francisco, CA, United

March 25, 2007 3:01 PM
 

Product News from the Core Team said:

As you may have noticed that , db4o is starting to throw runtime exception since version 6.2. It's taking

May 15, 2007 7:23 AM
 

db4o Newsletter said:

The efficiency of Transparent Persistence is added to .NET LINQ provider New “Stable” Release 6.4 is

May 22, 2008 10:17 PM
Anonymous comments are disabled