Exception Handling
Best practices for error logging and debugging with Triton, including exception handling patterns and debugging strategies.
Best Practices for Error Logging
Exception Logging Patterns
Basic Exception Logging
try {
// Business logic
processAccount(account);
} catch (Exception e) {
// Always log errors
Triton.instance.addError(TritonTypes.Area.Accounts, e);
}Advanced Exception Logging with Context
public class ExceptionHandlingService {
public static void processWithExceptionHandling(Id recordId) {
// Set up template for error handling
Triton.instance.setTemplate(
Triton.makeBuilder()
.category(TritonTypes.Category.Apex)
.type(TritonTypes.Type.Backend)
.area(TritonTypes.Area.Accounts)
.relatedObject(recordId)
);
try {
// Business logic
processRecord(recordId);
} catch (DmlException e) {
// Handle DML-specific errors
Triton.instance.log(
Triton.instance.fromTemplate()
.exception(e)
.summary('DML operation failed')
.details('recordId=' + recordId + ', operation=update')
);
throw e;
} catch (CalloutException e) {
// Handle callout-specific errors
Triton.instance.log(
Triton.instance.fromTemplate()
.exception(e)
.summary('External API call failed')
.details('recordId=' + recordId + ', endpoint=external-service')
);
throw e;
} catch (Exception e) {
// Handle all other errors
Triton.instance.log(
Triton.instance.fromTemplate()
.exception(e)
.summary('Unexpected error occurred')
.details('recordId=' + recordId + ', context=record-processing')
);
throw e;
}
}
}Real-World Exception Handling Example
LWC Exception Handling
Exception Types and Handling
DML Exceptions
Callout Exceptions
Custom Exceptions
Debugging Strategies
Stack Trace Analysis
Performance Monitoring
Best Practices
Error Logging Guidelines
Exception Handling Patterns
Debugging Support
Last updated