Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [exceptions]

An exception is an occurrence in an application process that requires deviation from the program's normal flow.

Filter by
Sorted by
Tagged with
5 votes
5 answers
573 views

Imagine I have a function like this (written in Java): void sayHello(String firstName, String lastName) { if (firstName == null) { throw new IllegalArgumentException("first name is ...
J-bob's user avatar
  • 357
12 votes
6 answers
4k views

The basics: what I know I understand the basics of exceptions: If a function cannot perform its assigned task, it can signal it by throwing an exception, When writing a function, one must make sure ...
Eternal's user avatar
  • 245
4 votes
2 answers
502 views

I am trying to write a backend for use with a completely text based UI for one shot operations (eg. python scriptname arg, executes that argument and exits) and a GUI using the curses library for some ...
Hugo Schongin's user avatar
3 votes
3 answers
546 views

I am starting a project in Java and ran into the following situation. The application requires a persistence layer for a certain document type. This could be a MySql database, an AWS Dynamo DB ...
Matias Grioni's user avatar
1 vote
4 answers
546 views

In order to make sure methods fail fast under invalid arguments, I usually do validation at the start of a method. If I'm verifying multiple predicates, this leads to a few lines of checkNotNull or ...
EarthTurtle's user avatar
4 votes
5 answers
3k views

I have the following method, which needs to return a List, but exceptions might occur along the way, and I don't want to handle them in my application, mainly because I don't even know how to handle ...
MasterTJ123's user avatar
0 votes
2 answers
729 views

We manage a backend application behind a FastAPI REST controller with multiple endpoints. A member of our team decided to use a middleware on the application which parses the body of the response for ...
Blue_Elephant's user avatar
5 votes
7 answers
584 views

Consider the following scenario. I have an interface IService: public interface IService { void DoSomething(); } with an implementation: public class Implementation : IService { // This might ...
Codisattva's user avatar
5 votes
6 answers
2k views

A long time ago I was in a class and the professor had us write individual exception handlers for every possible error. This seems almost impossible to do when developing large pieces of software ...
FourierFlux's user avatar
1 vote
5 answers
253 views

Consider the two following examples: public Something fetchSomething(String key) { if(somethingsMap.containsKey(key)) { return somethingsMap.get(key); } throw new ...
steros's user avatar
  • 121
3 votes
1 answer
824 views

I have been tasked with the title above. There is currently zero exception handling. There are 100+ threads, all created from main(). Exceptions won't percolate up to main() - they won't leave the ...
Mawg's user avatar
  • 4,308
1 vote
2 answers
2k views

how could we advise the web client about a non-recoverable exception thrown by the persistence adapter ? At first sight, I would define a domain exception to be thrown by the persistence adapter and ...
hjoly's user avatar
  • 21
0 votes
1 answer
305 views

We have a GraphQL server which sends data to the front end client. We have other tenants who will use our sever and host their code. I want to create a system where they all can create any custom ...
user415612's user avatar
0 votes
1 answer
140 views

I need some guidance on how to send error responses to client from WebAPI controller for an update operation. I need to check if data is changed and if it has duplicate data. I have service class that ...
Sunny's user avatar
  • 945
2 votes
1 answer
223 views

Given that there are no checked exceptions in Kotlin, are Result types the correct way to indicate an exception occurred to the caller? For example, I have the following function in my code: suspend ...
Adam's user avatar
  • 272
-2 votes
3 answers
911 views

I came across a piece of legacy code, almost on the line of this (sample) int foo() { try { int id = generateID(); if (isIDUsed(id)) throw id; return id; } catch (int ...
Zoso's user avatar
  • 251
1 vote
2 answers
682 views

There's a section about use of checked exceptions in Josh Bloch Effective Java and I find it a bit abstract to understand what he means by saying "when a user can recover from it". ...
TMOTTM's user avatar
  • 119
1 vote
1 answer
191 views

The below code sample given is for Salesforce but it is close to Java and you should be able to understand easily what I am trying to ask here. AccountController.getAccountsThatMeetSpecificCrtieria is ...
user3978's user avatar
  • 221
0 votes
1 answer
100 views

My application follows Clean Architecture wherein the Application Layer wraps the Domain Layer. I try to adhere to DDD more-so as a "guiding light" than a strict rulebook. Within the Domain ...
John Hall's user avatar
  • 163
2 votes
3 answers
974 views

I am curious about the utility of something like monads in the C# world. My experience with these kinds of things is mainly through Rust but I'm a dotnet dev for work I was thinking about the ...
Jeremy Farmer's user avatar
10 votes
8 answers
2k views

I just finished a discussion with colleagues regarding the use of exceptions in code. Here is the code (pseudocode) that they had written: resp = fetch(URL) if resp.status_code != 200: return ...
Daniel's user avatar
  • 527
5 votes
6 answers
4k views

Over the years I've many times seen folks enumerate error codes for exceptions in Java. I generally have felt this leads to more tedious code and does not provide value. For example, there will be an ...
Kirby's user avatar
  • 271
3 votes
4 answers
1k views

A simplified version of my code looks like this: def process( object ): try: if suitedForA( object ): try: methodA( object ) except: ...
Jann Poppinga's user avatar
0 votes
1 answer
145 views

Scenario I have a system where a user can upload an Excel file which is validated and then used to provide data for the application. There are two distinct operations I need to handle with this file: ...
donquixote's user avatar
21 votes
4 answers
4k views

C++ features deterministic order of calling destructors up the call stack until the exception is handled somewhere. To my knowledge, neither Java nor (object oriented) Python provide this. In those ...
Vorac's user avatar
  • 7,189
1 vote
3 answers
344 views

When catching and wrapping an exception in PHP, assuming the new exception doesn't have a meaningful code of its own, should you also use the caught exception's code value? or the default value? In ...
TravisCarden's user avatar
-2 votes
2 answers
13k views

I understand that a SocketTimeoutException (I'm in Java, but I guess it's the same in just about every major language) happens after a server or client doesn't respond after a period of time, let say ...
Mickael Bergeron Néron's user avatar
1 vote
2 answers
418 views

Let's take a hypothetical system, a state based, exceptions thrown from persistence layer or other outer layer, should propagate to ui layer through domain layer. Domain need not know about this ...
duckydude20's user avatar
-1 votes
1 answer
774 views

I'm starting to run into this sort of dilemma while many third-party APIs, but I will use MongoDB for my examples. Consider the following code: var settings = MongoClientSettings....
Saturn's user avatar
  • 3,937
1 vote
1 answer
733 views

I have a service that performs a series of actions based on user information (name, address, etc), one of the problems is that the User entity comes from a legacy third party API (as a repository) ...
Thiago Dias's user avatar
5 votes
6 answers
531 views

Context Let's say I have a navigation service that allows me to navigate to a page. The Navigate method is async because an animation (about 250ms) is involved. public interface INavigator { ...
Batesias's user avatar
  • 274
14 votes
14 answers
8k views

Take this constructed example: def fetch_person(person_id, country_code=None): if is_fully_qualified(person_id): return person_source_1.fetch_person(person_id) else: return ...
André Christoffer Andersen's user avatar
0 votes
3 answers
203 views

I'm writing an application based on a RESTful API located in a server (written in Python). An Android app will access the API endpoints to get, post, put or delete data. The usual. The server has a ...
ismarlowe's user avatar
0 votes
3 answers
1k views

Exogenous exceptions are that kind of exception that are unavoidable because they are throwed outside of our system's pristine logic. A good practice is to throw wrapped exceptions in lower layers ...
Scover's user avatar
  • 5
1 vote
2 answers
267 views

Ive got a boot sequence that needs to check some registry values, they may or may not be present, so each check needs to be wrapped in its own try-except. I try to avoid nesting as I think it can lead ...
pstatix's user avatar
  • 1,047
2 votes
1 answer
190 views

In my company, we are using Event Sourcing pattern to implement a storage for all changes to the price of a booking. Across the company, different services might try to append events to a booking ...
JamesBoyZ's user avatar
  • 245
8 votes
10 answers
720 views

I've always been taught that fatal exceptions (indicating problems that cannot be solved programmaticaly) and boneheaded exceptions (resulting from bugs in my code) should not be caught, should not be ...
gaazkam's user avatar
  • 4,529
7 votes
2 answers
4k views

I am focusing on learning better design and wondered if this code is good or an anti-pattern? The function Validate() returns true if the data is correct, else it will throw an exception with a ...
proeng's user avatar
  • 103
4 votes
3 answers
5k views

C#'s primary error handling mechanism are exceptions and try pattern. We don't have access to discriminated unions yet like in case of F# and Rust Option<T> and Result<T, E> types. The ...
Konrad's user avatar
  • 1,569
27 votes
14 answers
9k views

I'm writing an application in C#. I'm facing an InvalidConstraintException, but from that Exception, I seem not to be able to access the Constraint, causing the Exception. That specific question is ...
Dominique's user avatar
  • 1,844
0 votes
2 answers
173 views

I have a checkout process that 1) creates a user account in Stripe and my database, 2) creates a paymentMethod in Stripe and logs the last4 in the database, 3) creates the subscription in Stripe and ...
germanshedder's user avatar
0 votes
2 answers
358 views

Consider the following code: public class User { private String password; public void changePassword( String oldPassword, String newPassword) throws ...
George Z.'s user avatar
  • 705
6 votes
3 answers
1k views

Suppose of having a library exposing the following piece of functionality: public static class AwesomeHelpers { public static async Task<int> ComputeSomethingImportAsync(CalculationInputs ...
Enrico Massone's user avatar
0 votes
1 answer
233 views

When it comes to exception handling, there are many guidelines and best practices on the web. On of them is to throw early, catch late, or even Don't Catch. So when facing an exception, the current ...
mperktold's user avatar
  • 151
2 votes
2 answers
3k views

I have a question regarding validations and exceptions in DDD. I have a ValueObject say, PasswordText which takes a string argument in it's constructor. Checks if the string matches the password ...
honey_ramgarhia's user avatar
4 votes
3 answers
10k views

In JavaScript, if I have try catch blocks in a function that is meant to be called from another function, should I also put them in the calling function or just let the called functions handle them. ...
Russ Bain's user avatar
  • 143
1 vote
2 answers
380 views

I have a code-coverage requirement of of a certain percentage, and face the following tradeoff: Should I sacrifice in-method sanity checks and error handling for ease of (unit-) testability? Lets ...
MPIchael's user avatar
  • 269
1 vote
2 answers
802 views

I am currently thinking about some design choices regarding exception handling. My current architecture looks a little like this: You can see that I have a UI where a try-catch middleware is cathing ...
David Mason's user avatar
1 vote
2 answers
163 views

I am reading a lot about patterns and code structure and something that bothers me is BeanValidation's way to handle errors. I like Java and think that BeanValidation is easy to use, but it seems to ...
Apollo's user avatar
  • 139
-2 votes
4 answers
163 views

I am writing an API function using DRF where I want the API execution to stop if it fails in any of the steps and return an appropriate response. So I created a custom exception which takes an error ...
gowthz's user avatar
  • 111

1
2 3 4 5
13