Kaydet (Commit) fd60dd52 authored tarafından Noel Grandin's avatar Noel Grandin

java: improve use of WrappedTargetException to set cause properly

since we introduced the new constructors that pass the cause all the
way up to java.lang.Throwable.
Also simplify some exeception printing sites, because Throwable
will correctly print out child exceptions for us.

Change-Id: Ibbecce3c6f971fbc80d6de2052ab4f33a4503c0a
üst 07c54fff
...@@ -43,7 +43,7 @@ public final class Relay implements XRelay, XSource { ...@@ -43,7 +43,7 @@ public final class Relay implements XRelay, XSource {
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw e; throw e;
} catch (com.sun.star.uno.Exception e) { } catch (com.sun.star.uno.Exception e) {
throw new WrappedTargetRuntimeException(e.getMessage(), this, e); throw new WrappedTargetRuntimeException(e, e.getMessage(), this, e);
} catch (Exception e) { } catch (Exception e) {
throw new com.sun.star.uno.RuntimeException(e, "", this); throw new com.sun.star.uno.RuntimeException(e, "", this);
} }
...@@ -55,7 +55,7 @@ public final class Relay implements XRelay, XSource { ...@@ -55,7 +55,7 @@ public final class Relay implements XRelay, XSource {
context.getServiceManager().createInstanceWithContext( context.getServiceManager().createInstanceWithContext(
"com.sun.star.bridge.BridgeFactory", context)); "com.sun.star.bridge.BridgeFactory", context));
} catch (com.sun.star.uno.Exception e) { } catch (com.sun.star.uno.Exception e) {
throw new WrappedTargetRuntimeException(e.getMessage(), this, e); throw new WrappedTargetRuntimeException(e, e.getMessage(), this, e);
} }
new Thread() { new Thread() {
@Override @Override
......
...@@ -77,7 +77,7 @@ public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch ...@@ -77,7 +77,7 @@ public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch
} catch (com.sun.star.uno.RuntimeException e) { } catch (com.sun.star.uno.RuntimeException e) {
throw e; throw e;
} catch (com.sun.star.uno.Exception e) { } catch (com.sun.star.uno.Exception e) {
throw new WrappedTargetRuntimeException( throw new WrappedTargetRuntimeException(e,
"wrapped: " + e.getMessage(), this, e); "wrapped: " + e.getMessage(), this, e);
} }
} }
......
...@@ -135,7 +135,7 @@ public class OptionsEventHandler { ...@@ -135,7 +135,7 @@ public class OptionsEventHandler {
try { try {
return handleExternalEvent(aWindow, aEventObject); return handleExternalEvent(aWindow, aEventObject);
} catch (com.sun.star.uno.Exception e) { } catch (com.sun.star.uno.Exception e) {
throw new WrappedTargetException(sMethod, this, e); throw new WrappedTargetException(e, sMethod, this, e);
} }
} }
......
...@@ -77,7 +77,7 @@ public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch ...@@ -77,7 +77,7 @@ public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch
} catch (com.sun.star.uno.RuntimeException e) { } catch (com.sun.star.uno.RuntimeException e) {
throw e; throw e;
} catch (com.sun.star.uno.Exception e) { } catch (com.sun.star.uno.Exception e) {
throw new WrappedTargetRuntimeException( throw new WrappedTargetRuntimeException(e,
"wrapped: " + e.getMessage(), this, e); "wrapped: " + e.getMessage(), this, e);
} }
} }
......
...@@ -688,11 +688,11 @@ XMultiPropertySet ...@@ -688,11 +688,11 @@ XMultiPropertySet
} }
catch (java.lang.NoSuchFieldException e) catch (java.lang.NoSuchFieldException e)
{ {
throw new WrappedTargetException("Field does not exist", this, e); throw new WrappedTargetException(e, "Field does not exist", this, e);
} }
catch (java.lang.IllegalAccessException e) catch (java.lang.IllegalAccessException e)
{ {
throw new WrappedTargetException("", this ,e); throw new WrappedTargetException(e, "", this ,e);
} }
return ret; return ret;
} }
...@@ -808,7 +808,7 @@ XMultiPropertySet ...@@ -808,7 +808,7 @@ XMultiPropertySet
} }
catch(java.lang.Exception e) catch(java.lang.Exception e)
{ {
throw new WrappedTargetException("PropertySet.setPropertyValueNoBroadcast", this, e); throw new WrappedTargetException(e, "PropertySet.setPropertyValueNoBroadcast", this, e);
} }
} }
/** Retrieves the value of a property. This implementation presumes that the values are stored in member variables /** Retrieves the value of a property. This implementation presumes that the values are stored in member variables
......
...@@ -479,7 +479,7 @@ public final class PropertySetMixin { ...@@ -479,7 +479,7 @@ public final class PropertySetMixin {
} catch (UnknownPropertyException e) { } catch (UnknownPropertyException e) {
continue; continue;
} catch (WrappedTargetException e) { } catch (WrappedTargetException e) {
throw new WrappedTargetRuntimeException(e, throw new WrappedTargetRuntimeException(e.getCause(),
e.getMessage(), object, e.TargetException); e.getMessage(), object, e.TargetException);
} }
s[n++] = new PropertyValue(handleMap[i], i, value, state[0]); s[n++] = new PropertyValue(handleMap[i], i, value, state[0]);
...@@ -742,7 +742,7 @@ public final class PropertySetMixin { ...@@ -742,7 +742,7 @@ public final class PropertySetMixin {
{ {
throw new PropertyVetoException(e, name, object); throw new PropertyVetoException(e, name, object);
} else { } else {
throw new WrappedTargetException( throw new WrappedTargetException(e.getCause(),
e.getMessage(), object, e.TargetException); e.getMessage(), object, e.TargetException);
} }
} }
...@@ -774,7 +774,7 @@ public final class PropertySetMixin { ...@@ -774,7 +774,7 @@ public final class PropertySetMixin {
{ {
throw new UnknownPropertyException(e, name, object); throw new UnknownPropertyException(e, name, object);
} else { } else {
throw new WrappedTargetException( throw new WrappedTargetException(e.getCause(),
e.getMessage(), object, e.TargetException); e.getMessage(), object, e.TargetException);
} }
} }
......
...@@ -130,7 +130,7 @@ public class SampleDialog extends WeakBase implements XServiceInfo, XJobExecutor ...@@ -130,7 +130,7 @@ public class SampleDialog extends WeakBase implements XServiceInfo, XJobExecutor
createDialog(); createDialog();
} }
catch ( Exception e ) { catch ( Exception e ) {
throw new com.sun.star.lang.WrappedTargetRuntimeException( e.getMessage(), this, e ); throw new com.sun.star.lang.WrappedTargetRuntimeException( e, e.getMessage(), this, e );
} }
} }
} }
......
...@@ -46,7 +46,6 @@ import com.sun.star.lang.XComponent; ...@@ -46,7 +46,6 @@ import com.sun.star.lang.XComponent;
import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.IllegalArgumentException; import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException; import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.WrappedTargetRuntimeException;
import com.sun.star.beans.XPropertySet; import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.StringPair; import com.sun.star.beans.StringPair;
...@@ -863,28 +862,9 @@ public class DocumentMetadataAccess ...@@ -863,28 +862,9 @@ public class DocumentMetadataAccess
// utilities ------------------------------------------------------------- // utilities -------------------------------------------------------------
public void report2(Exception e)
{
if (e instanceof WrappedTargetException)
{
System.out.println("Cause:");
Exception cause = (Exception)
(((WrappedTargetException)e).TargetException);
System.out.println(cause.toString());
report2(cause);
} else if (e instanceof WrappedTargetRuntimeException) {
System.out.println("Cause:");
Exception cause = (Exception)
(((WrappedTargetRuntimeException)e).TargetException);
System.out.println(cause.toString());
report2(cause);
}
}
public void report(Exception e) { public void report(Exception e) {
System.out.println("Exception occurred:"); System.out.println("Exception occurred:");
e.printStackTrace(System.err); e.printStackTrace(System.err);
report2(e);
fail(); fail();
} }
......
...@@ -20,8 +20,6 @@ package complex.writer; ...@@ -20,8 +20,6 @@ package complex.writer;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.WrappedTargetRuntimeException;
import com.sun.star.lang.EventObject; import com.sun.star.lang.EventObject;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent; import com.sun.star.lang.XComponent;
...@@ -165,29 +163,10 @@ public class LoadSaveTest ...@@ -165,29 +163,10 @@ public class LoadSaveTest
public void disposing(EventObject Event) { } public void disposing(EventObject Event) { }
} }
void report2(Exception e)
{
if (e instanceof WrappedTargetException)
{
System.out.println("Cause:");
Exception cause = (Exception)
(((WrappedTargetException)e).TargetException);
System.out.println(cause.toString());
report2(cause);
} else if (e instanceof WrappedTargetRuntimeException) {
System.out.println("Cause:");
Exception cause = (Exception)
(((WrappedTargetRuntimeException)e).TargetException);
System.out.println(cause.toString());
report2(cause);
}
}
void report(Exception e) { void report(Exception e) {
System.out.println("Exception occurred:"); System.out.println("Exception occurred:");
System.out.println(e.toString()); System.out.println(e.toString());
e.printStackTrace(System.err); e.printStackTrace(System.err);
report2(e);
// failed(); // failed();
} }
......
...@@ -25,8 +25,6 @@ import com.sun.star.uno.XComponentContext; ...@@ -25,8 +25,6 @@ import com.sun.star.uno.XComponentContext;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.IllegalArgumentException; import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.WrappedTargetRuntimeException;
import com.sun.star.beans.XPropertySet; import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.Pair; import com.sun.star.beans.Pair;
import com.sun.star.beans.StringPair; import com.sun.star.beans.StringPair;
...@@ -549,28 +547,9 @@ public class RDFRepositoryTest ...@@ -549,28 +547,9 @@ public class RDFRepositoryTest
// utilities ------------------------------------------------------------- // utilities -------------------------------------------------------------
public void report2(Exception e)
{
if (e instanceof WrappedTargetException)
{
System.out.println("Cause:");
Exception cause = (Exception)
(((WrappedTargetException)e).TargetException);
System.out.println(cause.toString());
report2(cause);
} else if (e instanceof WrappedTargetRuntimeException) {
System.out.println("Cause:");
Exception cause = (Exception)
(((WrappedTargetRuntimeException)e).TargetException);
System.out.println(cause.toString());
report2(cause);
}
}
public void report(Exception e) { public void report(Exception e) {
System.out.println("Exception occurred:"); System.out.println("Exception occurred:");
e.printStackTrace(); e.printStackTrace();
report2(e);
fail(); fail();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment