Skip to main content

Questions tagged [exceptions]

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

4votes
2answers
428views

Control flow and communication with two separate frontends (maybe with exceptions)?

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
3votes
3answers
383views

How to handle checked exceptions on interface contract in Java

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
1vote
4answers
348views

Combining multiple input validations into one exception

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
4votes
5answers
3kviews

The best way to handle exceptions?

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
0votes
2answers
601views

Explain why it's bad to use a middleware to coat error messages as exceptions

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
5votes
7answers
480views

Exceptions and the Liskov Substitution Principle

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
5votes
6answers
2kviews

When to write a custom exception handler?

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
1vote
5answers
210views

End method in normal flow versus exception flow

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

How to catch every exception in a multi-threaded C++ app with the minumum of code?

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,246
1vote
2answers
2kviews

Exception Handling in Hexagonal Architecture

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

How to correctly extend runtime exception?

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

Return response from controller or raise exception from service

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
2votes
1answer
188views

Is returning Result types the standard way of dealing with errors in Kotlin?

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
-2votes
3answers
740views

Locally throw exception and handle it

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
  • 241
0votes
2answers
617views

Is Authentication a good use case for a checked exception according to Effective Java (Bloch)?

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

153050per page
close