Interface CtTry

All Superinterfaces:
Cloneable, CtBodyHolder, CtCodeElement, CtElement, CtQueryable, CtStatement, CtVisitable, FactoryAccessor, Serializable, SourcePositionHolder, TemplateParameter<Void>
All Known Subinterfaces:
CtTryWithResource
All Known Implementing Classes:
CtTryImpl, CtTryWithResourceImpl

public interface CtTry extends CtStatement, TemplateParameter<Void>, CtBodyHolder
This code element defines a try statement. Example:
     try {
        System.out.println("foo");
     } catch (Exception ignore) {}
 
  • Method Details

    • getCatchers

      List<CtCatch> getCatchers()
      Gets the catchers of this try.
    • setCatchers

      <T extends CtTry> T setCatchers(List<CtCatch> catchers)
      Sets the catchers of this try.
    • addCatcher

      <T extends CtTry> T addCatcher(CtCatch catcher)
      Adds a catch block.
    • removeCatcher

      boolean removeCatcher(CtCatch catcher)
      Removes a catch block.
    • getBody

      CtBlock<?> getBody()
      Gets the try body.
      Specified by:
      getBody in interface CtBodyHolder
    • getFinalizer

      CtBlock<?> getFinalizer()
      Gets the finalizer block of this try ( finally part).
    • setFinalizer

      <T extends CtTry> T setFinalizer(CtBlock<?> finalizer)
      Sets the finalizer block of this try ( finally part).
    • clone

      CtTry clone()
      Description copied from interface: CtElement
      Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtCodeElement
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtStatement