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.
    • addCatcherAt

      CtTry addCatcherAt(int position, CtCatch catcher)
      Adds a catch block at the specified position in the try statement. Behaves similarly to List.add(int, Object).
      Parameters:
      position - the position at which the catcher is to be inserted
      catcher - the catch statement to be inserted
      Returns:
      this try statement
      Throws:
      IndexOutOfBoundsException - if the position is out of range (position < 0 || position > number of catchers)
    • 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