The article explains best practices for safely closing resources in Java, including using finally blocks, null checks, separate try‑catch for each resource, avoiding return or System.exit in finally, not throwing exceptions from finally, and preferring try‑with‑resources with code examples.
This guide explains how Spring Boot’s @Retryable annotation enables elegant, annotation‑driven retry logic, covering dependency setup, enabling retry, method annotation with configurable parameters, recovery handling via @Recover, and important AOP‑related considerations to avoid common pitfalls.
This article explains why and how to deliberately throw exceptions during Spring Boot development to test transaction rollbacks and global error handling, comparing a manual approach with IntelliJ IDEA's built‑in "Throw Exception" debugging feature.
This article demonstrates how to create a reusable global exception handling mechanism for Spring Boot applications by defining a unified response class, custom business exception, error enumeration, and a @RestControllerAdvice handler, complete with code examples and testing guidance.
This article explains three common situations where Spring's @Transactional annotation becomes ineffective—non‑public methods, internal self‑calls, and swallowed exceptions—detailing the underlying proxy mechanism, code examples, test results, and practical workarounds to ensure proper transaction management.
This guide explains why excessive try‑catch blocks hurt Spring Boot projects, introduces a unified response class, custom business exception, error enumeration, and a global @RestControllerAdvice handler, providing clean, reusable error handling with sample code and test usage.
This article explains several often‑confused Spring annotations—including the differences between @Component and @Bean, the injection behaviors of @Autowired versus @Resource, the roles of @Component, @Repository, @Service, and @Controller, the purpose of @Configuration and @ControllerAdvice, and provides practical code examples for each.
This article explains how to replace repetitive try‑catch blocks in Java Spring applications with a clean, unified exception handling approach that leverages @ControllerAdvice, custom Assert utilities, enum‑based error codes, and standardized response objects to improve code readability and maintainability.
This article explains how to replace repetitive try‑catch blocks in Java Spring applications with a unified @ControllerAdvice error handler, lightweight Assert utilities, and enum‑based error codes, resulting in cleaner code, consistent JSON responses, and easier maintenance across backend services.
This article explains how to replace repetitive try‑catch blocks in Java Spring applications with a unified exception handling strategy that leverages @ControllerAdvice, custom Assert utilities, and enum‑driven error codes to produce clean, maintainable backend code and consistent error responses.
This article explains several Python techniques—using identical break conditions, flag variables, exceptions, loop‑else clauses, and function returns—to exit nested loops, demonstrated through a prime‑number game where the program stops when a non‑prime input is entered.
This article explains Java exception categories, how Spring's @Transactional decides which exceptions trigger a rollback, and provides practical annotation configurations to control rollback behavior for both checked and unchecked exceptions.
This article explains Java exception classification, distinguishes checked and unchecked exceptions, and demonstrates how to configure Spring's @Transactional annotation to control rollback behavior, including examples of rollbackFor, notRollbackFor, and propagation settings, while highlighting common pitfalls with try‑catch blocks.
Learn how to replace repetitive if…else statements in Java by leveraging Java 8’s functional interfaces—Supplier, Consumer, Runnable, and Function—through clear examples, custom interfaces, and utility methods that streamline exception handling, branch processing, and null checks for cleaner, more maintainable code.
This article explains how to customize authentication and resource server exception messages in Spring Security OAuth2, covering the creation of custom translators, entry points, and filters, with step‑by‑step code examples and testing procedures for handling username/password errors, grant type errors, client credential errors, token expiration, and insufficient permissions.
This article explains eight typical situations—such as using non‑transactional storage engines, missing Spring bean registration, non‑public methods, self‑invocation, absent transaction manager, incorrect propagation settings, swallowed exceptions, and wrong exception types—that cause the @Transactional annotation in Spring to appear ineffective, and provides practical solutions for each.
This article explains how CPUs receive interrupt numbers through hardware, exceptions, or the INT instruction, describes the structure and purpose of the Interrupt Descriptor Table, and details the stack operations and control‑flow steps the processor performs to handle and return from an interrupt.
This article examines three frequent challenges when using Feign in Spring Cloud—where to place the client, whether to wrap Feign interfaces, and how to handle business exceptions—offering a detailed comparison of two call styles, a ResponseBodyAdvice‑based wrapper solution, and a custom error decoder to propagate original exceptions.
This article demonstrates how to combine multiple exception types in a single catch block and how to employ Java's try‑with‑resources construct to automatically close resources, providing complete code examples drawn from Nacos's BaseDatabaseOperate class.
This article explains how to combine Retrofit with Kotlin coroutines on Android, compares the traditional RxJava method with coroutine-based implementations, and presents two encapsulation techniques—using a DSL and leveraging CoroutineExceptionHandler—to simplify asynchronous network calls and centralize error handling.
This article introduces the Loguru library as an elegant, concise alternative to Python's built‑in logging, demonstrating installation, basic usage, file configuration, formatting, filtering, rotation, retention, compression, serialization, and advanced exception tracing with code examples.
This article presents a set of coding "military rules" covering topics such as avoiding magic numbers, limiting method parameters, proper resource release, specific exception handling, and precise arithmetic, followed by practical development efficiency tips and resource links for further learning.
This article examines why excessive null‑checking in Java code creates clutter, distinguishes when null is a valid response versus an error, and offers practical techniques such as asserts, exceptions, empty collections, and the Null Object pattern to write cleaner, safer code.
This tutorial explains why parameter validation is essential in Spring Boot APIs, shows how to integrate the JSR‑303 Validator, demonstrates custom annotations, group validation, and simplifies error responses with a global exception handler, providing complete code examples for each step.
To improve Java‑Kotlin interoperability, the article recommends treating Kotlin exceptions as unchecked while enforcing Java‑style checked‑exception discipline through lint checks, using specific custom exceptions, avoiding broad catches or throws of Throwable, logging via a Monitor, and never returning from finally blocks to reduce crashes.
This article explains how JavaScript and C++ exceptions work in Node.js native addons, compares traditional v8::TryCatch handling with the newer Maybe-based approach in node-addon-api v4.1.0, and shows practical code examples for reliable error management.
This article explains how to use Spring Boot's @ControllerAdvice and @ExceptionHandler annotations to implement clean, global exception handling, covering basic usage, controller‑specific handlers, and ordered advice for multiple handlers, with practical code examples and diagrams.
This article explains why global exception handling is needed in Spring MVC, outlines its application scenarios, compares AOP with the simpler @ControllerAdvice/@ExceptionHandler approach, and provides detailed code examples for custom response objects, validation handling, and transaction rollback strategies to improve code cleanliness and maintainability.
This article explains why a caught javax.validation.ConstraintViolationException in a Spring @Transactional method does not stop the transaction from rolling back, and shows how to debug the flow with logs and breakpoints to understand the underlying commit process.
This article explains how to distinguish between valid and invalid null returns in Java, recommends using assertions or exceptions for erroneous nulls, suggests returning empty collections or objects, and demonstrates the Null Object pattern with code examples to eliminate repetitive null‑pointer checks.
This article explains Python exception propagation, demonstrates nested try blocks and function calls, shows how to define and raise custom exceptions, and illustrates re‑throwing exceptions within handlers, all backed by clear code examples and output screenshots.
This article presents ten essential Java exception‑handling best practices—including proper resource cleanup, using specific exception types, documenting throws clauses, providing clear messages, catching the most specific exceptions first, avoiding Throwable, logging wisely, and preserving original causes—to improve code readability, reliability, and maintainability.
This article explains how to configure Spring Boot to handle default and custom exceptions globally, covering logging of error mappings, adding Fastjson and Freemarker dependencies, configuring properties, defining error entity and custom exception classes, creating an error template, implementing a @ControllerAdvice handler, and testing with sample controllers and JSON responses.
This article outlines practical guidelines for designing and implementing enterprise‑grade APIs, covering request/response definitions, unified error handling, interceptor chains, token‑based authentication, rate limiting, load balancing, clustering, caching, and strategies for achieving high concurrency and high availability.
This article explains Alibaba’s Java guidelines for using @Transactional, categorizes checked and unchecked exceptions, shows how Spring’s default rollback behavior works, and provides practical examples of configuring rollback rules, avoiding common pitfalls, and best practices for applying @Transactional in backend Java applications.
This article explains why proper exception handling is essential for high‑quality JavaScript, contrasts using return codes with real exceptions, shows clean versus dirty code examples, and offers practical guidelines such as defining custom exception hierarchies, handling Promise rejections, and providing contextual error information.
This article explains typical situations where Spring @Transactional annotations fail—such as non‑public methods, beans not managed by the container, internal method calls, non‑RuntimeException throws, caught exceptions without rethrow, incorrect propagation settings, and unsupported MyISAM storage—and provides concrete code examples and fixes to ensure proper transaction behavior.
This article explains typical reasons why @Transactional may not work in Spring applications—such as non‑public methods, beans not managed by the container, internal method calls, non‑RuntimeException throws, swallowed exceptions, wrong propagation settings, and unsupported MySQL storage engines—and provides concrete code examples and fixes for each case.
This article explains how to create a reusable backend foundation for new Spring Boot projects by assembling common utilities such as Swagger API documentation, MyBatis‑Plus code generation, unified response objects, pagination helpers, custom exception handling, multi‑environment Maven and Spring profiles, logback configuration, and a Jenkins pipeline.
This article outlines essential Java exception‑handling best practices, covering resource cleanup with finally or try‑with‑resources, declaring specific exceptions, documenting throws clauses, providing descriptive messages, catching the most specific exceptions first, avoiding catching Throwable, never ignoring or double‑logging exceptions, and correctly wrapping exceptions without losing the original cause.
This article explains several hidden dangers of using finally in Java try‑catch‑finally blocks, such as return statements, code that appears not to execute, execution order with System.err, and cases where finally may be skipped, and provides concrete example code and practical solutions.
This article explains Python's advanced class features—including static methods, class methods, property decorators, special dunder methods, reflection utilities, dynamic attribute manipulation, metaclass creation, and exception handling—illustrated with clear code examples and practical usage tips.
This article explains how malicious newline characters in logged usernames can cause log injection, demonstrates a simple input‑sanitizing method, shows how to use Log4j2's %enc{%m}{CRLF} pattern and a custom ThrowablePatternConverter to ensure all log messages and exception stacks remain on a single safe line.
This article explains why excessive null‑checking in Java code is problematic, distinguishes valid versus invalid null returns, and presents better alternatives such as assertions, throwing exceptions, returning empty collections or objects, and applying the Null Object pattern with concrete code examples.
Java developers often close resources manually using try-catch-finally, but since JDK 7 the try‑with‑resources construct automates this process; this article explains the traditional pattern, demonstrates the new syntax, shows how to implement custom Closeable classes, and reveals the compiler‑generated bytecode that preserves original exceptions via addSuppressed.
This article explains the main reasons why Spring's @Transactional annotation may become ineffective—including non‑public method modifiers, internal method calls, and swallowed exceptions—provides code examples, test cases, and a deep dive into the underlying proxy and AOP mechanisms.
This article provides a comprehensive overview of Java's exception architecture, detailing the hierarchy of Throwable, Error, and Exception, distinguishing checked and unchecked exceptions, explaining key keywords, and offering best practices with code examples for effective error handling.
Best PracticesChecked ExceptionsException Handling
This article provides a comprehensive overview of Java's exception mechanism, covering the Throwable hierarchy, differences between Errors, Exceptions, checked and unchecked types, key keywords, practical code examples, and best‑practice guidelines for writing robust, maintainable Java code.
This article examines the challenges of chain performance testing without branch handling, proposes logical branch controls and synchronized test termination, and provides concrete Java code examples to improve reliability and accuracy of load‑testing pipelines.
The article recounts a real‑world scenario where two backend engineers discover that many bugs blamed on the B system actually stem from missing validation and exception handling in the A system, illustrated with pseudo‑code showing a try‑catch block that logs and returns a generic failure message.
This article summarizes Flutter exception types—including Dart, Engine, and Framework errors—explains how to capture them with try‑catch, Zone.runZoned, and FlutterError.onError, and details comprehensive gray‑release configurations, downgrade mechanisms, and operational metrics for maintaining reliable mobile experiences.
This article explains how abstracting front‑end data into reusable models—illustrated with product, SKU, and exception handling examples—improves code safety, testability, and maintainability for complex applications such as a multi‑variant e‑commerce product publishing page.
This article explains why exception handling in Java is challenging and presents ten practical best‑practice guidelines—including using finally or try‑with‑resources, declaring specific exceptions, documenting throws, providing clear messages, catching specific exceptions first, avoiding Throwable, logging properly, and preserving original causes—to write more robust and maintainable code.
This tutorial walks through setting up the PassJava project, covering microservice architecture, service discovery with Nacos, remote calls via OpenFeign, API gateway configuration, OSS file storage integration, and centralized exception handling, providing detailed code examples and configuration steps for each component.
This tutorial explains why a unified JSON format is needed in a Spring Boot project, defines a standard {code, message, data} schema, shows how to create a Result enum and generic wrapper class, and demonstrates global handling with @ResponseResultBody, ResponseBodyAdvice, and @ExceptionHandler for clean, consistent API responses.
This article demonstrates how to use Spring Boot AOP to automatically record operation and exception logs by defining log tables, adding the AOP starter dependency, creating a custom @OperLog annotation, implementing an aspect that captures request details and errors, and applying the annotation to controller methods, providing a clean, reusable logging solution for Java backend applications.
This article explains Java exception categories, distinguishing checked from unchecked exceptions, and shows how Spring's @Transactional annotation controls transaction rollbacks, including configurations for rolling back on checked exceptions, preventing rollback on unchecked ones, and best practices for applying @Transactional in backend services.
The article explains Java’s try‑with‑resources feature as syntactic sugar that the compiler rewrites into a try‑finally structure with sophisticated exception handling, demonstrates the generated bytecode, clarifies AutoCloseable versus Closeable, and offers best‑practice guidelines for reliable resource management.
This article explains how to replace repetitive try‑catch‑finally blocks with a unified global exception handling mechanism in Spring Boot, covering its evolution since Spring 3.x, classification of exceptions, the exact matching order, and a complete code example for developers.
This article explains how to replace verbose try‑catch blocks in Java with behavior‑parameterized lambda expressions and functional interfaces, providing a cleaner way to handle both runtime and checked exceptions while also demonstrating file‑reading using try‑with‑resources and lambdas.
This guide walks through building a Spring MVC backend that accepts multiple image uploads, returns them for preview, and covers front‑end HTML, JavaScript handling, multipart configuration, and common pitfalls such as parameter naming, file size limits, and global exception handling.
This article demonstrates how to design a non‑intrusive, unified JSON response structure for Spring Boot applications, defines a standard Result wrapper and status enum, shows static factory methods, and explains global handling via @ResponseResultBody, @RestControllerAdvice, and centralized exception processing.
This article explains how to simplify Java exception handling by leveraging behavior parameterization, lambda expressions, and functional interfaces, demonstrating a clean wrapper for checked exceptions and a try‑with‑resources file‑to‑string conversion that keeps business logic free of boilerplate try‑catch blocks.
This article demonstrates how to construct a well‑structured Spring Boot backend API by integrating request validation with Hibernate Validator, implementing global exception handling, defining custom exceptions, and standardizing responses using a unified response object and response‑body advice.
This article demonstrates how to simplify Java exception handling by leveraging behavior parameterization, functional interfaces, and lambda expressions, and applies the same technique to streamline file‑reading code with try‑with‑resources and lambda‑based processing.
This article explains the complexities of exception handling across various backend scenarios—such as message queues, RPC services, mobile and PC clients—offering practical guidelines on when to catch, rethrow, use error codes, or employ alternatives like Java Optional to improve code clarity and system reliability.
This article explains Java exception classifications, how Spring's @Transactional handles checked and unchecked exceptions, and provides practical configurations to control transaction rollbacks, while offering best‑practice notes on annotation placement and method design.
This article explains how to write robust Java code by applying defensive programming techniques such as guard clauses, proper exception handling, validator usage, assertions, and the DRY principle, while illustrating each concept with clear code examples and practical guidelines.
This article explains Java exception classification, the difference between checked and unchecked exceptions, and how to correctly configure Spring's @Transactional annotation to control rollback behavior for various exception types, including best practices for placement and method design.
This article reviews several of the most popular Java questions on StackOverflow, explaining branch prediction for sorted arrays, why char[] is safer than String for passwords, handling NullPointerException, deterministic random strings, historic timezone quirks, creating an uncatchable exception, and the differences between HashMap, TreeMap and LinkedHashMap, highlighting practical lessons for developers.
Android captures uncaught Java exceptions using Thread.UncaughtExceptionHandler, first logging details with a system LoggingHandler then terminating the app via KillApplicationHandler, converting the Throwable into an ApplicationErrorReport sent to ActivityManagerService and stored in /data/system/dropbox, while developers can view the same FATAL EXCEPTION stack trace in logcat to diagnose and fix the root cause.
The article explains how defensive programming in Java—using guard clauses, validators, and side‑effect‑free assertions—prevents errors, outlines proper exception handling by distinguishing checked from unchecked exceptions, and reinforces the DRY principle, urging developers to abstract repeated logic after three occurrences.
This article explains how Java 14's JEP 358 enhances NullPointerException by providing detailed messages that pinpoint the exact null variable, how to enable this feature with a JVM flag, and the technical and security considerations involved.
This article explains how to write robust Java code by applying defensive programming, using guard clauses, proper exception handling, validator patterns, assertions, and the DRY principle, offering concrete code examples and practical advice for building reliable software.
This article explains how Java's finally block always runs before a method returns, demonstrates the effect of return statements placed before, inside, or after finally with code examples, and clarifies the differences among final, finally, and finalize.
This article explains the design and implementation of the Haishen crash monitoring platform for iOS, covering its system architecture, data collection, parsing, aggregation, routing, SDK features, exception handling, stack capture, startup crash detection, and upload mechanisms to quickly expose, locate, and fix crashes.
This article explains Java's throw‑catch mechanism, the three core principles of exception handling, and demonstrates how to design a custom exception hierarchy and a Spring Boot @ControllerAdvice‑based global handler to simplify error processing and improve code maintainability.
A SpringBoot project’s custom validator introduced a severe remote code execution vulnerability when a single line of code interpolated user input, illustrating the importance of rigorous input validation, internationalized error handling, and security scanning before deployment.
This article examines when Java's finally block executes, explores cases where it may be skipped, analyzes its interaction with return statements and exceptions, and demonstrates how return values are affected through multiple code examples.
The article explains how to replace repetitive try‑catch blocks with a unified exception handling mechanism in Spring Boot by leveraging @ControllerAdvice, custom BaseException, enum‑driven error codes, Assert utilities, and standardized response objects to improve code readability and maintainability.
This article provides a concise, step‑by‑step checklist of common Git exceptions—including file recovery, branch deletion, commit amendment, branch renaming, commit rollback, merge reversal, and branch restoration—along with the exact commands and explanations needed to resolve each situation efficiently.
This tutorial explains how to define, implement, and throw custom Java exceptions, providing complete example code, step‑by‑step creation instructions, and a practical demo that integrates the custom exception into a JSON‑processing method.
This article explains how to replace repetitive try‑catch blocks in Java Spring applications with a unified exception handling strategy that leverages @ControllerAdvice, custom Assert utilities, and enum‑driven error codes to produce cleaner, more maintainable backend code.
This article demonstrates how to consolidate exception handling in a Spring Cloud microservice using @RestControllerAdvice, @Slf4j, and @ExceptionHandler, defines a unified error code enum, and provides test scenarios with sample code and API requests.
This article explains nine essential best‑practice guidelines for handling exceptions in Java, covering resource cleanup, specific exception types, documentation, informative messages, catch ordering, avoiding Throwable, proper logging, and exception wrapping to improve code readability and reliability.
This article presents common error patterns and proper techniques for handling Java exceptions, illustrating why returning null, catching generic exceptions, swallowing Throwables, and misusing finally blocks are problematic, and provides clear, correct examples to improve exception management in Java applications.
This article examines recurring “connection holder is null” errors in Druid’s connection pool, explains how the holder is assigned and cleared, analyzes two real‑world cases—long‑running transactions and killed connections—and offers practical configuration recommendations to prevent the issue.
The article explains why Java developers often litter code with null‑checks, distinguishes when null is a valid response versus an error, and proposes using assertions, exceptions, empty collections, or the Null Object pattern to write cleaner, safer code.
Best PracticesException HandlingNull Object pattern
This article explains how to replace noisy try‑catch blocks with Spring's @ControllerAdvice and custom Assert utilities, using enums for error codes, unified response structures, and practical MyBatis‑Plus examples to achieve clean, maintainable backend exception handling.
This article demonstrates how to replace repetitive try‑catch blocks in Java Spring applications with a unified exception handling approach that leverages @ControllerAdvice, custom Assert utilities, and enum‑based error codes to produce clean, maintainable, and internationalized error responses across controllers and services.
The article provides a thorough walkthrough of ARMv8 exception handling, describing the four exception levels (EL0‑EL3) and their dedicated stack and status registers, distinguishing synchronous and asynchronous faults, and detailing the vector table, entry routine, ESR‑based type decoding, handling steps such as do_mem_abort, and context restoration, illustrated with a Data Abort case.
This article provides a comprehensive overview of Java exception handling, covering the exception hierarchy, key keywords, common interview questions, code examples, and best‑practice guidelines for declaring, throwing, and catching exceptions effectively in Java applications.
Best PracticesException HandlingInterview questions
This article demonstrates how the Magpie open‑source suite can be used to migrate the Anjuke App’s “YouLiao” module to Flutter, covering project setup, hybrid engineering, module integration, UI component reuse, theme management, logging, and exception handling to improve development efficiency and cross‑platform consistency.
This article explains the proper use of Java exceptions, distinguishing between checked and unchecked exceptions, showing when to throw them, how to design APIs that avoid misuse, and offering guidelines for documenting and handling exceptions effectively.
This tutorial walks through deploying FastAPI in production, covering router inclusion as blueprints, handling multiple HTTP methods, integrating SQLAlchemy for database operations, applying Pydantic data validation, and implementing robust exception handling for a reliable backend service.
This article presents a comprehensive Python fundamentals guide covering common standard libraries, built‑in data types, the with statement, mutable vs immutable types, date handling, word counting, file deletion, custom exceptions, error handling, bug‑fix strategies, and key language feature differences between Python 2 and 3.
Exception HandlingPython2 vs Python3context manager
The article shares insights from reviewing thousands of code submissions, highlighting frequent errors such as swallowing exceptions, overusing generic string types, and misusing nulls, and recommends concrete type usage, proper exception handling, Optionals, and "unlifting" techniques to improve code quality and maintainability.
This article explains what CPU interrupts are, distinguishes synchronous and asynchronous types, describes the role of APIC controllers, and details the step‑by‑step initialization of the Interrupt Descriptor Table and related interrupt handling mechanisms in the Linux kernel.