From 415e303ac283df8d694b311f4f8df08f6e79cf0e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 16 Apr 2021 06:40:35 +0200 Subject: [pr 2702] finishing the `@StandardException` feature. * rewritten how it works a bit: Now compatible with parent exceptions that don't have the Throwable variants. * rewritten how it works a bit: You can now provide the full constructor only; the rest will forward to it. * fixing up style. * rewrite the docs. --- .../features/experimental/StandardException.html | 23 +++++++++++++++++++--- website/templates/features/experimental/index.html | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'website/templates/features') diff --git a/website/templates/features/experimental/StandardException.html b/website/templates/features/experimental/StandardException.html index 25324c4b..1484154d 100644 --- a/website/templates/features/experimental/StandardException.html +++ b/website/templates/features/experimental/StandardException.html @@ -10,9 +10,19 @@ <@f.overview>

- This annotation is intended to be used on subclasses of java.util.Throwable. For each of the four constructors in Throwable, it will generate a corresponding constructor in the target class, that simply forwards its argument to its super-counterpart. + Put this annotation on your own exception types (new classes that extends Exception or anything else that inherits from Throwable. This annotation will then generate up to 4 constructors: +

+

+ Each constructor forwards to the full constructor; you can write any or all of these constructors manually in which case lombok + will not generate it. The full constructor, if it needs to be generated, will invoke super(message); and will then + invoke super.initCause(cause); if the cause is not null.

- If any of those constructors is manually overriden, it is simply skipped. This allows applying special treatment such as annotations. + There are few reasons not to put this annotation on all your custom exceptions.

@@ -30,7 +40,14 @@ <@f.smallPrint>

- Although such situation is unlikely to occur, this annotation can technically be applied to any class for which all four expected constructors are defined in a superclass. + Lombok will not check if you extend an actual exception type. +

+ Lombok does not require that the class you inherit from has the Throwable cause variants, because not all exceptions + have these. However, the `Parent(String message)` constructor as well as the no-args constructor must exist. +

+ There is a very slight functional difference: Normally, invoking new SomeException(message, null) will initialize + the cause to be no cause, and this cannot be later changed by invoking initCause. However, lombok's + standard exceptions do let you overwrite an explicit no-cause with initCause later.

diff --git a/website/templates/features/experimental/index.html b/website/templates/features/experimental/index.html index 34dd3bb4..a8430d8d 100644 --- a/website/templates/features/experimental/index.html +++ b/website/templates/features/experimental/index.html @@ -77,7 +77,7 @@ <@main.feature title="@StandardException" href="StandardException"> - TODO + Standard.. Exceptional? This is not just an oxymoron, it's convenient! -- cgit