diff --git a/platform/extensions/src/com/intellij/openapi/extensions/ExtensionException.java b/platform/extensions/src/com/intellij/openapi/extensions/ExtensionException.java index 90eeeae2103d..2df2c7fd14d5 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/ExtensionException.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/ExtensionException.java @@ -17,9 +17,20 @@ package com.intellij.openapi.extensions; import org.jetbrains.annotations.NotNull; +/** + * This exception is thrown if there is a critical problem with some loaded extension. Use this exception inside 'intellij.platform.extensions' + * module only, in other parts of IntelliJ Platform and its plugins use {@link com.intellij.diagnostic.PluginException#createByClass} instead. + * + * @see com.intellij.openapi.extensions.ExtensionInstantiationException + */ public class ExtensionException extends RuntimeException{ private final Class myExtensionClass; + public ExtensionException(@NotNull String message, @NotNull Class extensionClass) { + super(message); + myExtensionClass = extensionClass; + } + public ExtensionException(@NotNull Class extensionClass) { super(extensionClass.getCanonicalName()); diff --git a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java index df35bdffe7c8..199a2c595102 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/impl/ExtensionPointImpl.java @@ -198,7 +198,7 @@ public abstract class ExtensionPointImpl implements ExtensionPoint, Iterab if (adapter != null) { message += ". It came from " + adapter; } - throw new RuntimeException(message); + throw new ExtensionException(message, extension.getClass()); } } @@ -788,7 +788,7 @@ public abstract class ExtensionPointImpl implements ExtensionPoint, Iterab myExtensionClass = extensionClass = extClass; } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new ExtensionInstantiationException(e, myDescriptor); } } return extensionClass; diff --git a/platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java b/platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java index c70bdade1802..08313c7d5fdb 100644 --- a/platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java +++ b/platform/extensions/src/com/intellij/openapi/util/KeyedExtensionFactory.java @@ -1,10 +1,11 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.util; +import com.intellij.openapi.diagnostic.ControlFlowException; +import com.intellij.openapi.extensions.ExtensionInstantiationException; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.KeyedFactoryEPBean; import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.util.ExceptionUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -71,7 +72,7 @@ public abstract class KeyedExtensionFactory { throw e; } catch (Exception e) { - throw new RuntimeException(e); + throw new ExtensionInstantiationException(e, epBean.getPluginDescriptor()); } } return null; @@ -104,14 +105,18 @@ public abstract class KeyedExtensionFactory { } } catch (InvocationTargetException e) { - ExceptionUtil.rethrowUnchecked(e.getCause()); - throw new RuntimeException(e); + Throwable t = e.getCause(); + if (t instanceof ControlFlowException && t instanceof RuntimeException) throw (RuntimeException)t; + throw new ExtensionInstantiationException(e, epBean.getPluginDescriptor()); } catch (RuntimeException e) { - throw e; + if (e instanceof ControlFlowException) { + throw e; + } + throw new ExtensionInstantiationException(e, epBean.getPluginDescriptor()); } catch (Exception e) { - throw new RuntimeException(e); + throw new ExtensionInstantiationException(e, epBean.getPluginDescriptor()); } } }