54,208 questions
Best practices
1
vote
8
replies
144
views
When to choose between throwing exceptions or returning return codes?
This question is brought about by the below examples. I have approached a couple of people for their opinions, but still would like some more help and context from the general community.
Here is an ...
Best practices
0
votes
5
replies
87
views
Custom vs standard exceptions in Python library design: when to use which?
Should I use custom exceptions in my library or just standard Python exceptions?
I'm building a Python library for video processing and I'm uncertain about exception handling design. Specifically, I'm ...
1
vote
2
answers
186
views
How to catch AccessViolationException in .NET 8 and gracefully exit the application?
Part of my code throws AccessViolationException; the code is not in my control; I cannot fix the problem. When this exception is thrown, my application crashes. I am working with Console application ...
1
vote
1
answer
49
views
Extra word in ARM v8-M stackframe
I'm writing a busfault handler for STM32-U5 which acc.to STM should be an Arm v8-M architecture.
And acc.to Arm https://developer.arm.com/documentation/107706/0100/Exceptions-and-interrupts-overview/...
3
votes
2
answers
201
views
Can I throw a C++ exception in a Windows API callback function?
Suppose, I have a try/catch in the wWinMain() function, which calls some Windows API functions, e.g. CreateWindowExW(), GetMessageW(), TranslateMessage(), DispatchMessageW(). The Windows API will call ...
1
vote
1
answer
131
views
C++20: How to safely catch and access exceptions thrown by coroutines with co_await?
I'm experiencing a segmentation fault when trying to access exception details (e.what()) in a catch block after co_awaiting a coroutine that throws an exception. The exception is successfully caught, ...
0
votes
2
answers
209
views
LINQ SingleOrDefault, but without throwing exceptions
I am looking for a custom LINQ operator here. I have an array of file paths and I want to find their common parent folder. In case the files are not located in the same folder, I want to throw an ...
1
vote
1
answer
181
views
Why is try/catch within nested for loops substantially slowing down execution time? [duplicate]
I'm working on a tool to segment features from a grey scale image and as part of this I want to perform a gaussian blur. This is basically a way of learning more about C# and the underling image ...
5
votes
2
answers
409
views
Should I use std::rethrow_exception in my catch block, rather than directly rethrowing it?
In my code, I have something like:
try { do_stuff(); }
catch(my_exception_class& e) {
if (not can_ignore_exception(e)) {
throw e;
}
log_or_do_nothing(e);
}
A static analyzer (...
1
vote
1
answer
140
views
Exception traceback with custom exception
I have the following code to enhance a class-level exception with subclass information:
class SomeClass:
def __new__(cls):
class ExWithClsInfo(RuntimeError):
def __init__(self, ...
5
votes
1
answer
227
views
how to catch Java exceptions using a C++ launcher?
I am writing a client application using Java Swing. I am quite confused about how a launcher can capture JVM crash information when the JVM crashes.
The hs_err_pid[PID].log file is not generated. I ...
2
votes
2
answers
171
views
Is it valid to rethrow an unhandled C++ coroutine exception with `throw;`?
Is the following code valid in a C++ coroutine promise object?
void
promise_type::unhandled_exception() noexcept
{
try {
// re-throw current exception
throw;
} catch (const std::exception &...
-2
votes
1
answer
115
views
PHP try-catch ineffective for mb_convert_encoding() function [duplicate]
I have the following code in a CLI PHP script. (The value in $mime_encoded_text actually comes from a message header, but for the sake of clarity, I have simplified here) :
$mime_encoded_text = "...
Best practices
0
votes
13
replies
6k
views
Is there a best practice on how to mimic defer/finalize blocks which can throw exceptions and should then throw nested exceptions
I'm trying to implement these requirements:
I have to execute functions i cannot modify.
Unfortunately, the functions also needs a specific global state which needs to be set before calling the ...
0
votes
1
answer
45
views
How should I set up a "RestExceptionHandler" for xhr requests and a "ErrorController" for non xhr requests in spring boot 3.5?
I am upgrading a rather big application from Spring Boot 2.7.18 to Spring Boot 3.5.6.
In this application there is an ExceptionController which is intended to handle exceptions
caused by non xhr ...
Best practices
0
votes
7
replies
203
views
What is the Pythonic way to handle invalid user input in a while loop?
import random
number_to_guess = random.randint(1, 10)
while True:
guess = input("Guess a number between 1 and 10: ")
# This crashes if 'guess' is not a number
if int(guess) == ...
Best practices
1
vote
3
replies
192
views
Can I modify the Message of a caught Delphi Exception object and then re-raise it?
The title says it, but here is an example:
try
// ...
raise EFileNotFoundException.Create('File not found!');
except
on E: EFileNotFoundException do begin
E.Message := Format('"%s":...
1
vote
1
answer
72
views
how to make socket server propagate exceptions up to TaskGroup where they're started from?
How to make exceptions thrown from a socket server running in a task group task be propagated up to its parent TaskGroup? With given example, I'd expect to see the error raised from ...
Advice
0
votes
2
replies
59
views
Better solutions for reseting 'is_running' flag to 0 when an exception occurs during code execution in python
I have a python code with below structure:
try:
# Check if ETL is running
check_isrunning_sms_journals = "select nvl(d.is_running,0) as is_running from running_etl_table d where ...
Advice
0
votes
0
replies
46
views
What should I replace a newline character with when newlines aren't allowed?
I'm building a hobby chess engine that communicates through the UCI protocol. This is communication done through standard out/in of the program, with each line representing a single command.
One of ...
4
votes
1
answer
161
views
Java ExecutorService detect asap thread fail
I have to run x asynchronous threads , which can last several minutes each.
They ALL have to terminate properly without exceptions.
If one fails I have to stop them all immediately and not wait ...
2
votes
1
answer
70
views
Calling `sys.excepthook` manually with `sys.last_exc`
The signature of sys.excepthook is
sys.excepthook(type, value, traceback)
so a natural way to call it is
sys.excepthook(sys.exc_type, sys.exc_value, sys.exc_traceback)
But as of Python 3.12, ...
Best practices
0
votes
0
replies
103
views
Java exception handling (best practices)
I'm starting out with Java and Spring Boot, and I have a fairly simple question that always raises doubts for me, as I always like to follow best practices.
I have a Controller layer where I create ...
0
votes
1
answer
188
views
Spring Boot 3.x — @RestControllerAdvice not catching custom exceptions
I recently upgraded to Spring Boot 3.5 (Jakarta packages) and noticed my global exception handler isn’t being triggered.
@RestController
public class UserController {
@GetMapping("/test")...
3
votes
1
answer
175
views
How to catch EXCEPTION_PRIV_INSTRUCTION from RDPMC directly in Assembly (and without SEH)?
I'm experimenting with measuring CPU's instructions latency and throughput on P and E cores using RDPMC on Win 11, something like that:
MOV ECX, 0x40000000 ; Instructions Counter
RDPMC ; Read ...
1
vote
0
answers
100
views
exception handling on different architectures
I have two questions about exception handling.
I read exception handling code of some real-time operating system (I mean assembly code). I note that on some architectures we allocate on stack more ...
0
votes
1
answer
67
views
WhenAll nested in WhenAny (or WhenAll with timeout) [duplicate]
The first exception does not block the execution:
public static async Task Main()
{
await Task.WhenAny(
Task.WhenAll(
Task.Run(() => throw new Exception(&...
1
vote
1
answer
83
views
How to handle error during customized scoped dependency injection
I have applied the multi-tenant location for EF Core database applying customize schema per tenant in my ASP.NET Core Web API project.
To do that the client send request through the API by setting ...
3
votes
1
answer
1k
views
Android project throws FileAnalysisException in onCreate method in Main Activity when adding OkHttp library
I've created an Empty Views Activity project in Android Studio, but as soon as I add the dependency in build.gradle.kts and try to launch the app, it throws an exception (see output). No code is ...
0
votes
1
answer
202
views
Getting Access violation exception thrown when setting up raylib with visual studio 2022
I wanted to learn game dev in C++ lately, so I decided to setup raylib in Visal Studio 2022 by following a tutorial online. I downloaded the latest release from the raylib github repo and configured ...
1
vote
1
answer
142
views
PPP_support.h error() function terminates program without printing custom message
I'm working through Bjarne Stroustrup's "Programming: Principles and Practice Using C++" and using the PPP_support.h file from the official website https://www.stroustrup.com/PPP_support.h
I ...
1
vote
1
answer
154
views
Can the compiler elide a const local copy of const& vector parameter?
Consider these two functions:
int foo(std::array<int, 10> const& v) {
auto const w = v;
int s{};
for (int i = 0; i < v.size(); ++i) {
s += (i % 2 == 0 ? v : w)[i];
...
0
votes
1
answer
766
views
How to deal with "DDGSException: No results found."
I tried to use DDGS to search for images in Jupyter Notebook with fastai, but the search seems to be not very stable. Most of time there turned out to be an ERROR:DDGSException: No results found.I ...
0
votes
1
answer
87
views
Catching an Alignment Check Exception on Windows
I'm trying to perform a misaligned memory read / write and catch it inside a __try and __except block.
After setting the RFLAGS.AC bit to 1, I perform the misaligned read which causes my program to ...
1
vote
2
answers
85
views
`Option.defaultValue` not working properly in f# when raising exception
I am trying to combine Option.defaultValue with failWith to get exception for None values:
printf "%A" (Some 1 |> Option.defaultValue (failwith "Error"))
But this code raise ...
1
vote
0
answers
78
views
How to receive the request object from webhook, Clientdisconnect exception. `Client disconnected before the server could read the request body`
I'm integrating the LINE messaging API with bot server. Likewise the Whatsapp Business API. To create the public URL, I used ngrok. Now whenever the user send the message to us, the LINE server send ...
4
votes
0
answers
131
views
Can I peek at an uncaught exception in the destructor of an object undergoing unwinding?
For debugging purposes, I would like to log the exception that is causing stack unwinding that lead to destruction of specific object. Something like this (pseudocode, obviously insufficient and not ...
1
vote
1
answer
160
views
Module loading logistics failed: file logistics/security/ir.model.access.csv could not be processed:
Exception: Module loading logistics failed: file logistics/security/ir.model.access.csv could not be processed:
No matching record found for external id 'model_logistics_order' in field 'Model'
No ...
0
votes
1
answer
76
views
I got java.io.FileNotFoundException when I call URL.openStream()
I have an URL for file downloading and it works perfectly on my Samsung Galaxy S10 (running Android 12), but the same app throws java.io.FileNotFoundException on my Google Pixel 9 with the latest ...
0
votes
1
answer
64
views
Can pathlib.Path().is_file() return True and open('foo', 'r') still raise an IOError?
Is it possible that pathlib.Path().is_file() returns True and the file is nevertheless not readable, i.e., open('foo', 'r') raises an IOError?
0
votes
0
answers
50
views
Error: "Unable to set the next statement. The attempt to unwind the callstack failed." in VS2022, but VS2019 works
I am unable to move the next statement pointer in VS2022 outside the catch block if an Exception is thrown.
If I run this code in a VS2022 (17.14.4) Unit Test Project (.Net 4.81), set a break point on ...
1
vote
0
answers
136
views
How to cancel a gRPC client streaming call cleanly without triggering RpcException, ObjectDisposedException, or InvalidOperationException?
I'm working on a gRPC client that continuously streams data (such as images) from a server. I use a CancellationToken to stop the stream when needed. While cancellation works, I consistently see ...
0
votes
1
answer
90
views
Why PersistenceException is thrown rather than EntityExistsException while trying to persist the same entity twice
I have set up a very simple Java web project (using NetBeans' Web Application template). It is deployed on Payara 6.2025.7 with a H2 database as a JTA data source.
I can't get EntityExistsException ...
1
vote
1
answer
134
views
Python asyncio/Telethon script suddenly stopped working after VSCode restart (Python 3.9.6 on macOS 12.7.6)
I have a Python script using asyncio (for Telethon) and until recently, it was running just fine in a Terminal inside VSCode.
However, an extension install prompted a VSCode restart and now I can't ...
1
vote
1
answer
79
views
Is it right to raise an error in except block in python? [closed]
I often see code like this:
try:
some_operation()
except Exception:
logger.error("An error occurred while running the operation")
raise Exception("A custom message")
...
1
vote
1
answer
136
views
JNDI Lookup Failing with Default Settings
I'm trying to implement a basic database web application in Netbeans using Java Server Faces and a Java Database. But whenever I try to deploy the application, I get the following error message:
...
0
votes
1
answer
243
views
Error NoClassDeffoundError: jakarta/servlet/ServletException with Spring Boot 3.4 and spring-boot-starter-webflux
I have the following configuration:
spring-boot-starter-parent: 3.4.7
spring-boot-starter-web (excluding spring-boot-starter-tomcat in order to have netty instead Tomcat)
spring-boot-starter-webflux`
...
0
votes
0
answers
79
views
C++Builder - linker errors trying to use __throwFileName and __throwLineNumber
I am trying to catch an exception and get the line and source file where the error occurred. I was using __throwLineNumber and __throwFileName and it compiles, but I am receiving linker errors:
[...
0
votes
1
answer
226
views
Memory exception when adding a node to a Win32 TreeView (in code that has been working for 2+ years!)
I am getting a memory exception in (unchanged) code that has been working for 2+ years (code is unchanged, in a Git repo).
Here's the code that is causing the exception:
HTREEITEM getTreeNode(HWND ...
2
votes
1
answer
588
views
How to fix DioException [connection timeout] in Flutter with AlgoliaSearch or Dio package?
I'm trying to fetch data using Algolia Search in Flutter and the data does get fetched the problem is that it gives the following error:
DioException (DioException [connection timeout]: The request ...