Sweet.apex

  • Docs
  • Tutorials
Docs Menu
  • Sweet.apex Core
    • Transpilation
    • Grammar
    • Command
    • Config
  • Features
    • Action
    • Apex Doc
    • Array Creation
    • Aspect
    • Cast
    • Default Value
    • Enum
    • File
    • Function
    • Identity
    • Injection
    • Lambda
    • Log
    • Mod
    • Not Null
    • Operator
    • Optional
    • Reflection
    • Rethrow
    • Switch
    • Template String
    • Template
    • Script
    • Tagged String
    • Annotation
    • Nullable
    • Var
    • Val
    • Map Access
    • Constructor
    • Transaction
    • Destructure
    • Import Static
    • Pipeline
    • Varargs
    • Patch
    • Import As
  • Plugin Development
    • Feature
    • Test Case

Rethrow Guide

Rethrow

Feature Overview

This feature catches any exception thrown from the method and rethrows the wrapped exception.

Prerequisite

None

Sweet Apex Example

public class Rethrow {
    @AuraEnabled
    @rethrow(AuraHandledException)
    public static void test() {
        System.debug('Rethrow exceptions');
    }
}

Transpiled Apex

public class Rethrow {
    @AuraEnabled
    public static void test() {
        try {
            System.debug('Rethrow exceptions');
        }
        catch(Exception e) {
            System.debug(LoggingLevel.Error, e.getStackTraceString());
            throw new AuraHandledException(e.getMessage());
        }
    }
}

Usage

@rethrow can only be used on methods.

Contribute on Github! Edit this section.