例外の操作
EngineRuntimeException のキャッチ
EngineRuntimeException または Java™ の標準的な例外をキャッチする例を以下に示します。
Java の例
Document doc2 = Factory.Document.createInstance(os, null);
doc2.checkin(null, null);
doc2.save(RefreshMode.NO_REFRESH);
try
{
doc2 = Factory.Document.fetchInstance(os, (doc2.get_Id()), null);
doc2.getProperties().putValue("DocumentTitle", "doc2");
}
catch (Exception ex)
{
if (ex instanceof EngineRuntimeException)
{
EngineRuntimeException fnEx = (EngineRuntimeException) ex;
if (fnEx.getExceptionCode().equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
{
doc2.save(RefreshMode.REFRESH);
doc2 = Factory.Document.fetchInstance(os, (doc2.get_Id()), null);
doc2.getProperties().putValue("DocumentTitle", "doc2");
}
else
// 必要な処理を挿入。ここでは単純に出力する
System.out.println("Exception: " + ex.getMessage());
}
else
// 標準の Java 例外
throw ex;
}
C# の例
IDocument doc2 = Factory.Document.CreateInstance(os, null);
doc2.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc2.Save(RefreshMode.NO_REFRESH);
try
{
doc2 = Factory.Document.FetchInstance(os, doc2.Id.ToString(), null);
doc2.Properties.GetProperty("DocumentTitle").SetObjectValue("doc2");
}
catch (System.Exception ex)
{
if (ex is EngineRuntimeException)
{
EngineRuntimeException fnEx = (EngineRuntimeException)ex;
if (fnEx.GetExceptionCode().Equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
{
doc2.Save(RefreshMode.REFRESH);
doc2 = Factory.Document.FetchInstance(os, doc2.Id.ToString(), null);
doc2.Properties.GetProperty("DocumentTitle").SetObjectValue("doc2");
}
else
// Do something.... ここでは単純に出力する
System.Console.WriteLine("Exception: " + ex.Message);
}
else
// 標準の C# 例外
throw ex;
}
例外コードの解釈
例外コードは、リソース・キーおよび関連付けられている例外メッセージ・テキストで構成されています。EngineRuntimeException インスタンスがある場合、EngineRuntimeException.getExceptionCode を使用して、リソース・キーおよびメッセージ・テキストを取得できます。
例外コード・キーの接頭部 (最初の下線文字 (「_」) の前にある冒頭の文字) は、例外の発生元のサブシステムを表します。関連付けられているメッセージ・テキストを取得するには、EngineRuntimeException.getMessage を使用します。
次のコード例により、可能性のある使用法を示します。
Java の例 (例外コード)
// EngineRuntimeException.getErrorCode を使用して、スローされた例外に基づき
// 処理を続行
Document doc1 = Factory.Document.createInstance(os, null);
doc1.checkin(null, null);
doc1.save(RefreshMode.NO_REFRESH);
try
{
doc1 = Factory.Document.fetchInstance(os, (doc1.get_Id()), null);
}
catch (EngineRuntimeException ex)
{
if (ex.getExceptionCode().equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
{
// 必要な処理を挿入。ここでは単純に出力する
System.out.println("Exception: " + ex.getMessage());
}
}
// The resulting exception: "Exception: Property Id not found in properties
// collection."
C# の例 (例外コード)
// EngineRuntimeException.getErrorCode を使用して、スローされた例外に基づき
// 処理を続行
IDocument doc1 = Factory.Document.CreateInstance(os, null);
doc1.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc1.Save(RefreshMode.NO_REFRESH);
try
{
doc1 = Factory.Document.FetchInstance(os, doc1.Id.ToString(), null);
}
catch (EngineRuntimeException ex)
{
if (ex.GetExceptionCode().Equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
// 必要な処理を挿入。ここでは単純に出力する
System.Console.WriteLine("Exception: " + ex.Message);
}
// The resulting exception: "Exception: Property Id not found in properties
// collection."
Java の例 (例外文字列)
// EngineRuntimeException.toString を使用して、ローカライズされたメッセージを含む、
// including the locale-specific message.
try
{
// ... code ...
}
catch (EngineRuntimeException ex)
{
if (ex.getExceptionCode().equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
{
// 必要な処理を挿入。ここでは単純に出力する
System.out.println(ex.toString());
}
}
// 結果の例外 (標準のロケール):
// "com.filenet.api.exception.EngineRuntimeException: API_PROPERTY_NOT_IN_CACHE:
// Property Id not found in properties collection."
C# の例 (例外文字列)
// EngineRuntimeException.toString を使用して、ローカライズされたメッセージを含む、
// including the locale-specific message.
try
{
// ... code ...
}
catch (EngineRuntimeException ex)
{
if (ex.GetExceptionCode().Equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
// 必要な処理を挿入。ここでは単純に出力する
System.Console.WriteLine(ex.ToString());
}
Java の例 (例外メッセージ)
// 必要に応じて EngineRuntimeException.getMessage または
// EngineRuntimeException.getLocalizedMessage, as required, to get only the locale-specific
// exception message. (両者はオーバーライドする java.lang.Throwable
// メソッドのみが異なる)
try
{
// ... code ...
}
catch (EngineRuntimeException ex)
{
if (ex.getExceptionCode().equals(ExceptionCode.API_PROPERTY_NOT_IN_CACHE))
{
// 必要な処理を挿入。ここでは単純に出力する
System.out.println(ex.getLocalizedMessage());
}
}
// The resulting exception (default locale): "Property Id not found in properties
// collection."
注: Content Engine の .NET API では、EngineRuntimeException.getMessage メソッドや EngineRuntimeException.getLocalizedMessage メソッドはサポートされません。