question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

some ideas about exception handling

See original GitHub issue

Hi @berndruecker, I have an idea about the exception handling strategy - DefaultCommandExceptionHandlingStrategy . We provide a default exception handling policy. If the user provides a custom exception handling policy, the custom policy will be activated.

  • interface
public interface CommandExceptionHandlingStrategy {
  void handleCommandError(JobClient jobClient, ActivatedJob job, Throwable throwable);
}
  • default handling strategy
public class DefaultCommandExceptionHandlingStrategy implements CommandExceptionHandlingStrategy {

  @Override
  public void handleCommandError(JobClient jobClient, ActivatedJob job, Throwable throwable) {
        //TODO
  }
}
  • Inject DefaultCommandExceptionHandlingStrategy when missing bean
  @Bean
  @ConditionalOnMissingBean(CommandExceptionHandlingStrategy.class)
  public CommandExceptionHandlingStrategy commandExceptionHandlingStrategy() {
    return new DefaultCommandExceptionHandlingStrategy();
  }

If the user provides a custom exception handling policy, the custom policy will be activated

public class CustomCommandExceptionHandlingStrategy implements CommandExceptionHandlingStrategy {

  @Override
  public void handleCommandError(JobClient jobClient, ActivatedJob job, Throwable throwable) {
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
berndrueckercommented, Nov 22, 2022

I looked into this again - as I need conditional beans for some other thing again. I think I found a really easy way to achieve this also with pure spring:


  public static class OnMissingCommandExceptionHandlingStrategy implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
      return context.getBeanFactory().getBeanNamesForType(CommandExceptionHandlingStrategy.class).length<=0;
    }
  }

  @Bean
  @Conditional(value=OnMissingCommandExceptionHandlingStrategy.class)
  public DefaultCommandExceptionHandlingStrategy commandExceptionHandlingStrategy() {
    return new DefaultCommandExceptionHandlingStrategy(backoffSupplier(), scheduledExecutorService());
  }

@lzgabel WDYT?

1reaction
berndrueckercommented, Dec 21, 2021

Thanks for the proposal - I am not sure if I come to work on this this year, but will take it into consideration 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Exception Handling? - SearchSoftwareQuality
Exception handling is the process of responding to unwanted or unexpected events when a computer program runs. Exception handling deals with these events...
Read more >
9 Best Practices to Handle Java Exceptions - Stackify
Handling Java exceptions isn't easy, especially for beginners. Read this post to understand exceptions and best practices for using them.
Read more >
Clean Code and the Art of Exception Handling - Toptal
Exception Handling : It's a Good Thing · Always create your own ApplicationError hierarchy · Never rescue Exception · Never rescue more exceptions...
Read more >
Exception handling - Wikipedia
In computing and computer programming, exception handling is the process of responding to the occurrence of exceptions – anomalous or exceptional conditions ...
Read more >
Topic: Exception Handling
Exceptional conditions are any unexpected occurrences that are not accounted for in a system's normal operation. It is difficult to protect a system...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found