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
0
votes
1answer
50 views

Exception handling for a page with multiple sections

Context: We have a page which is composed of multiple sections. Consider for e.g: A product page with Product details, prices, images & offers. All the sections are shown one after the other in ...
1
vote
5answers
162 views

Is this an anti pattern or misusing the interface default method?

Instead of checking the null and throwing exception each time we call findByOrderNumber method, I came up with this pattern by taking advantage of a default method, are there any patterns misused here ...
1
vote
1answer
80 views

What is better way to track mistakes in error-prone part of a feature?

That is quite specific circumstances I've come across, and I somewhat struggle to find proper way how to approach this. I'm given a class written in swift-language, which has a control property, like ...
0
votes
2answers
119 views

Is it good practice to throw exceptions in parsing functions

I basically read across the entire internet that exceptions are bad, slow and should be avoided whenever possible. This confuses me because I thought I have a "valid" case to use exceptions. Consider ...
3
votes
3answers
184 views

Should you define an equality test solely for testing?

Assume you have a class C. C defines a public method (member function) C::m1. Calling c.m1() (c is an instance of C) can either Return after mutating the object c it was called on. Throw an ...
4
votes
4answers
462 views

Throwing exception from constructor?

I have this NamePath class that accepts a string from some system path and tries to split it into two properties, Name and LastName. Is the code example below fine? I've read that throwing exceptions ...
1
vote
2answers
99 views

Is logging every exception with FirstChanceException event handler a bad practice?

I joined a company and the project I'm working on have an event handler that extends the FirstChanceException functionality to log the exceptions. The logs are stored in a file and not registered to ...
1
vote
1answer
44 views

Where to handle duplicate key exceptions in multy layer application

+-------------+ +--------+ +----------+ | repository +-------->+service +------->+controller| +-------------+ +-^------+ +------------+ +-------------+ | ...
-1
votes
2answers
57 views

Execute sequence of methods conditionally and log possible error

I'm not sure if this is the adequate site (maybe CodeReview?) but it's the only one here in StackExchange that have got a "clean code" tag ... There is no need for downvotes if this is not the correct ...
33
votes
9answers
6k views

Testing the wording of an Exception message

Doing a code review, I ran into this assertion in a unit test: assertThatThrownBy(() -> shoppingCartService.payForCart(command)) .isInstanceOfSatisfying(PaymentException.class, exception -&...
1
vote
1answer
41 views

Still catch “duplicate entry” exception of database even after pre-validation of user input?

Say, you pre-validate if a username already exist in a registration form in the application layer. E.g., You send back a nice "username already exist" error message to the user. While unlikely, there'...
4
votes
1answer
480 views

Error handling in Nest service layer

I would like to create a REST API with NestJs. But I want to add GraphQL as another top level layer later on. So for the start I have the basic layers controller, service and TypeORM repository. Let's ...
64
votes
12answers
20k views

Result object vs throwing exceptions

When sending a request to another module and expecting a result, it seems to me there are two ways of dealing with the 'non-happy paths'. Throw an exception Return a result object that wraps ...
2
votes
2answers
195 views

Where should I catch exceptions

I'm developing an application that has a backend (Java, Spring) and a frontend (TypeScript, Angular). The backend application provides with an OpenAPI-compatible API and performs certain operations ...
80
votes
17answers
13k views

Why should 'boneheaded' exceptions not be caught, especially in server code?

I am confused because in quite a few places I've already read that the so-called 'boneheaded' exceptions (ones that result from bugs in code) are not supposed to be caught. Instead, they must be ...
2
votes
0answers
99 views

c++ exceptions, should the caller add the context or provide it to the callee?

Here is a piece of code. Basically, I load some source files, all of them are compiled separately, and then I link all of them. LinkedObject loadObject(std::vector<std::string>& fileNames) {...
2
votes
3answers
188 views

Should a library throw exceptions that reveal its internal call stack?

While researching this question, I've found a lot of sources like this: Basically, it should be deemed a criminal offense to use "throw ex". The experts I'm seeing this from seem to be working ...
1
vote
3answers
514 views

Should exceptions be in the UML sequence diagram?

It the exceptions thrown in case of error are represented in the UML sequence diagram, would it make the UML sequence diagram too heavy? If they are not represented, how to tell about them?
6
votes
4answers
2k views

How to respect Single responsibility principle and use exception handling at the same time?

I am getting confused on how exactly should I be using exception handling inside a class that respects S-Principle. For example consider this code in C#: public class BcryptDecrypt { ...
1
vote
5answers
254 views

What is best way to handling exceptions without users see errors for technical supports?

Assuming you have a software which you gave to clients. Now we all know that exceptions can be saved to files, databases, and so on for tracing errors by technicians. As all engineers know, no Apps ...
2
votes
2answers
254 views

What is the difference between unit testing and handling exceptions

I have spent two full days now trying to understand the difference between unit testing and handling exception, but I can't get it. Things I have understood (or I think I have): Unit testing tests ...
1
vote
1answer
55 views

Do I need multiple exception classes for a Micro Service

I am developing a Micro Service which is going to be called/used internally. I'm trying to improve error handling, but got confused with two below approaches. Having multiple exception classes for ...
2
votes
1answer
76 views

Provide overall application status in global exception handler/crash report

In my UI application (WPF/C#, using MVVM design pattern), I have implemented a global exception handler which catches all unexpected (hence uncaught) exceptions and reports the application crash to ...
2
votes
1answer
93 views

Does it make sense to qualify an error as an HTTP error without an HTTP client-server communication

I am writing a C# client SDK to a REST Api. This SDK sends JSON-serialized models to the API, and implements a first level of verification of the parameters. If the verification fails, it throws an ...
30
votes
7answers
8k views

How to treat unhandled exceptions? (Terminate the application vs. Keep it alive)

What is best practice when a unhandled exceptions occurs in a desktop application? I was thinking about to show a message to the user, so that he can contact support. I would recommend to the user to ...
2
votes
2answers
243 views

Throw Custom Exception

First, I know - there are a lot of online resources that talk about the topic Exception handling - but yet there is still something that's unclear to me. Consider having this code in an external ...
0
votes
2answers
79 views

How to automatically triage production runtime errors before creating Jira issues?

How do "you" handle runtime incidents (say, a null-pointer exception, or an API input data validation failure) so that you (a) don't miss any, and (b) aren't spammed by duplicates? Are you doing log ...
3
votes
7answers
399 views

Should a base class take responsibility for wrapping incorrectly thrown exceptions that are part of the API documentation? [closed]

It is a common approach to use specialized exception types to indicate exceptional results of a method. These exception types are not considered to indicate a programming flaw, but, as I pointed out, ...
0
votes
1answer
131 views

Handling Currency getInstance throwing IllegalArgumentException

I have a class with a (simplified) method which returns a string like this : private String doStuff(String currencyCode, BigDecimal amount){ StringBuilder sb= new StringBuilder(); ...
2
votes
6answers
121 views

How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?

Consider class Crate that is a value object. Crate represents a valid 3-dimensional box. In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters ...
3
votes
3answers
475 views

Are Result objects the cleaner way to handle failure, than exceptions? [duplicate]

I was watching the following video by Vladimir Khorikov, which recommends to "Refactoring Away from Exceptions" pluralsight.com - Applying Functional Principles in C# - Refactoring Away from ...
1
vote
2answers
624 views

Exceptions versus guard clauses

I'm trying to get my head around Python exceptions. I've read quite a bit on the topic but can't get clear answers to some questions. In particular, I'm still not sure whether to use exceptions or ...
0
votes
1answer
355 views

How to output exception messages in GUI applications in order to decouple application code to GUI code?

I want to make GUI applications such that the non-GUI code is independent from the GUI one (let's say I'll use Java 8 and Swing for example). The goal is that I could hypothetically change the GUI ...
1
vote
1answer
2k views

Where would you handle exceptions: controller, service, repository?

I have been having this dilemma from time to time whenever I have to design or start a new project from scratch. I particularly like how Spring framework is organised in terms of classic software ...
1
vote
3answers
100 views

Exception handling philosophy when dealing with batches of input

I am handling a file with 1 million records and my customer creates this file from his code. I might receive hundreds of these files. I have to read these records and ingest them into a database. It ...
-2
votes
3answers
172 views

Try-catch in method or where the method is called? [closed]

I have the following method in Java: public method1() { //does something that might throw an exception } And then another method that calls the method above like so: public method2() { ...
3
votes
5answers
343 views

Should exceptions be only thrown if I intend to crash the program? [duplicate]

...I wanted to find the source before writing this Q, sadly I couldn't. My mental model was that exceptions were thought as an alternative to returning error codes from a function, which is the C ...
7
votes
6answers
4k views

Why do programming languages not let you use a try block without a catch block? [closed]

Why do languages demand catch blocks when they aren't needed? The compiler or parser complains with this code: try { const utils = require("applicationutils"); } But it is OK with this code: ...
-2
votes
3answers
689 views

Handling an exception thrown in a catch block [closed]

If I'm writing a method, in C# for example, I will use a try catch block. Let's say the method adds some numbers but I log exceptions in the catch block. What's the best way to handle an exception ...
47
votes
4answers
9k views

Exception propagation: When should I catch exceptions?

MethodA calls an MethodB which in turn calls MethodC. There is NO exception handling in MethodB or MethodC. But there is exception handling in MethodA. In MethodC an exception occurs. Now, that ...
1
vote
2answers
130 views

Should you “rebrand” the exception of the library you're using?

Say your making a library Foo that depends on a 3rd-party library Bar. Bar throws a custom exception \OtherVendor\Bar\CustomException. Is it recommended to just throw that exact exception to your ...
1
vote
1answer
331 views

Best practices for handling application specific exceptions?

Is it considered to be a good practice to convert all types of exceptions (exceptions from internal logic of application + exceptions from application's external dependencies - for example: File ...
65
votes
12answers
10k views

Having a flag to indicate if we should throw errors

I recently started working at a place with some much older developers (around 50+ years old). They have worked on critical applications dealing with aviation where the system could not go down. As a ...
0
votes
2answers
145 views

Should I track my handled exceptions?

Various analytics tools will track the number of handled and unhandled exceptions (crashes) that happen in an app. This obviously helps us find problems we didn't know existed and will fix it. Quite ...
4
votes
3answers
233 views

Is using exceptions to validate parameters a violation of using exceptions for control flow?

I was reading on SO and SESE about exceptions and control flow, but I can't seem to determine or figure out if using exceptions to validate parameters is a violation of that guideline. Suppose I had ...
1
vote
3answers
403 views

How to deal with an unknown situation in a system?

When a caller makes a call to a callee, exception's are used to inform the caller that something different has happened so that he could change the flow of the program if required. In that sense, ...
7
votes
6answers
2k views

Why is it bad to use exceptions for handling this type of validation? It seems like it makes the code so much cleaner

I'm working on a .NET Core REST API and I'm writing a service class to create new user accounts. I have the following code: public async Task<UserDto> RegisterNewUserAccount(...
1
vote
3answers
440 views

Is avoiding throwing an exceptions OK?

e.g I'm parsing whole Excel file with many rows, that has an column which contains Date. I'm not sure how to handle error-handling when it comes to parsing string to DateTime Here's an sample code ...
3
votes
4answers
2k views

Check if resource exists before inserting to the database or wait until the DAO throw the Exception?

I have two paths: /students /students/{id}/addresses ...with the following behavior: POST to /students - 201 Created (if successfully created the Student) POST to /students/{id}/addresses - 201 ...
1
vote
7answers
2k views

Is it a good practice to use self-defined exception?

Our team has different opinions about the practice of using self-defined exception for handling the business logic. Someone says it is good as the exception comes meaningful and readable, and the ...

1
2 3 4 5
12