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
4
votes
1answer
39 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 ...
25
votes
11answers
7k 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 ...
-1
votes
0answers
24 views

Logical issue with extending exceptions in php

With PHP I am using the following class structure for exceptions: class ProjectException extends Exception { ... logical code for handling exceptions, functions that are relevant to every ...
2
votes
2answers
187 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 ...
77
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
92 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
182 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
97 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
1k 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
240 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
183 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
53 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
74 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
92 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
218 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
64 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
378 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
75 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
120 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 ...
2
votes
3answers
332 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
407 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
171 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
796 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
94 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
171 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
338 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
421 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 ...
45
votes
4answers
8k 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
119 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
256 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 ...
64
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
218 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
375 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, ...
6
votes
6answers
1k 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
402 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 ...
2
votes
4answers
1k 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
1k 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 ...
0
votes
1answer
41 views

Reuse JSE checked exceptions as unchecked

Actually what i'm doing in my code base is duplicating already existing java checked exceptions like MalformedURLException.class by keeping the same exception name while inheriting from ...
0
votes
2answers
598 views

Is it beneficial to throw a caught IOException as an UncheckedIOException in order to prevent NullPointerException?

Not using UncheckedIOException, NullPointerException possible public void callerMethod() { Object result = ioMethod(); // call instance method of result } public Object ioMethod() { ...
1
vote
2answers
154 views

Is passing an ErrorMessage to be populated inside the receiving method an anti-pattern?

I come from a Java background, and my colleague is from .NET. We are working on a Java project and I saw him create a method like this: public Object myMethod(Object[] param1, ErrorMessage ...
4
votes
2answers
233 views

Verifying Parameters in Constructor or Service

I was reading on this SO page about when to check parameters when constructing an object. The accepted answer suggests throwing the exception from the constructor so that an invalid object cannot be ...
1
vote
5answers
804 views

Limits of Defensive Programming acknowledging that Exception Handling should be avoided

I've read Defensive Programming vs Exception Handling? and if/else statements or exceptions, but none contain something relevant to what I'm searching for. Taking into account that exception handling ...
0
votes
3answers
198 views

Too much logic in a nested catch block

My lead dev complained that I have too much logic in a nested catch block. My code goes something like this: try { // some setup and a network call } catch (CustomEx ex) { try { ...
0
votes
1answer
120 views

Simple but frequently throwing vs reasonable but rarely throwing vs complex but never throwing [duplicate]

A lot of code that's designed to convert or parse some data of type Foo into a Bar is written with the assumption that one wouldn't intentionally pass it invalid inputs. As such, it assumes that ...
3
votes
4answers
138 views

Passing a callback all the way down or throw an Exception?

I have a service, call it Service A, that is built on a Storage Layer, call it DB, that is 5-6 levels deep. This layer is depended upon by many other services. Service A is having memory issues and ...
8
votes
6answers
1k views

Should reused exceptions types be favored over single use ones?

Let's say I have Doors that are managed by a DoorService. The DoorService is in charge of opening, closing and locking the doors that are stored on the database. public interface DoorService { ...
3
votes
2answers
3k views

How to deal with exceptions in DLLs?

I recently started working on an existing project written in C++ Builder. The application consists of a MainModule that loads lots of modules (DLLs). The MainModule itself is a DLL (there is a small ...

1 2 3 4 5 12