Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2e9c43658e374d290a2de15d25134ac8 > files > 414

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Advanced Features|Exception Handling" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>How To Work With db4o Exceptions</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../../Resources/Code/prettify.js">
        </script>
        <script src="../../Resources/Code/lang-vb.js">
        </script>
        <script src="../../Resources/Code/jquery.min.js">
        </script>
        <script src="../../Resources/Code/ZeroClipboard.js">
        </script>
        <script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../index_CSH.html#advanced_topics/exceptions/how_to_work_with_db4o_exceptions.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../advanced_topics.htm">Advanced Features</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../exceptions.htm">Exception Handling</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">How To Work With db4o Exceptions</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1>How To Work With db4o Exceptions</h1>
        <p>Appropriate
exception handling will help you to create easy to support systems, saving your
time and efforts in the future. The following hints identify important
places for exception handling. Take also a look at the list of <a href="exception_types.htm">common db4o exceptions</a>.</p>
        <ol>
            <li value="1">
                <p>Opening a database file can throw a DatabaseFileLockedException.</p>
                <div class="codesnippet" MadCap:conditions="Primary.c#">
                    <pre class="prettyprint" xml:space="preserve">try
{
    IObjectContainer container = Db4oEmbedded.OpenFile("database.db4o");
}
catch (DatabaseFileLockedException e)
{
    // Database is already open!
    // Use another database-file or handle this case gracefully
}</pre>
                    <div class="codesnippet-meta">ImportantExceptionCases.cs: If the database is already open
			<div class="codedownload"><a href="../../CodeExamples/strategies/exceptions/Example-strategies-exceptions-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
                </div>
                <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
                    <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Try
    Dim container As IObjectContainer = Db4oEmbedded.OpenFile("database.db4o")
Catch e As DatabaseFileLockedException
    ' Database is already open!
    ' Use another database-file or handle this case gracefully
End Try</pre>
                    <div class="codesnippet-meta">ImportantExceptionCases.vb: If the database is already open
			<div class="codedownload"><a href="../../CodeExamples/strategies/exceptions/Example-strategies-exceptions-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
                </div>
            </li>
            <li value="2">
                <p>Opening a client connection can throw IOException.</p>
                <div class="codesnippet" MadCap:conditions="Primary.c#">
                    <pre class="prettyprint" xml:space="preserve">try
{
    IObjectContainer container = Db4oClientServer.OpenClient("localhost", 1337, "sa", "sa");
}
catch (Db4oIOException e)
{
    // Couldn't connect to the server.
    // Ask for new connection-settings or handle this case gracefully
}</pre>
                    <div class="codesnippet-meta">ImportantExceptionCases.cs: Cannot connect to the server
			<div class="codedownload"><a href="../../CodeExamples/strategies/exceptions/Example-strategies-exceptions-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
                </div>
                <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
                    <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Try
    Dim container As IObjectContainer = Db4oClientServer.OpenClient("localhost", 1337, "sa", "sa")
Catch e As Db4oIOException
    ' Couldn't connect to the server.
    ' Ask for new connection-settings or handle this case gracefully
End Try</pre>
                    <div class="codesnippet-meta">ImportantExceptionCases.vb: Cannot connect to the server
			<div class="codedownload"><a href="../../CodeExamples/strategies/exceptions/Example-strategies-exceptions-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
                </div>
            </li>
            <li value="3">
                <p>Working with <a href="../unique_constraints.htm">db4o-unique constraints</a> the commit may throw exceptions when the constraints are violated.</p>
                <div class="codesnippet" MadCap:conditions="Primary.c#">
                    <pre class="prettyprint" xml:space="preserve">container.Store(new UniqueId(42));
container.Store(new UniqueId(42));
try
{
    container.Commit();
}
catch (UniqueFieldValueConstraintViolationException e)
{
    // Violated the unique-constraint!
    // Retry with a new value or handle this gracefully
    container.Rollback();
}</pre>
                    <div class="codesnippet-meta">ImportantExceptionCases.cs: Violation of the unique constraint
			<div class="codedownload"><a href="../../CodeExamples/strategies/exceptions/Example-strategies-exceptions-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
                </div>
                <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
                    <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">container.Store(New UniqueId(42))
container.Store(New UniqueId(42))
Try
    container.Commit()
Catch e As UniqueFieldValueConstraintViolationException
    ' Violated the unique-constraint!
    ' Retry with a new value or handle this gracefully
    container.Rollback()
End Try</pre>
                    <div class="codesnippet-meta">ImportantExceptionCases.vb: Violation of the unique constraint
			<div class="codedownload"><a href="../../CodeExamples/strategies/exceptions/Example-strategies-exceptions-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
                </div>
            </li>
        </ol>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>