Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [exception]

An exception is a rarely occurring (exceptional!) condition that requires deviation from the program's normal flow.

Filter by
Sorted by
Tagged with
7 votes
1 answer
623 views

Wordle guesser, breaking out of loop by raising exception

After many years away from writing in Python, I am getting back into it. Specifically, I am trying to teach myself dataclasses. As an exercise I wrote a Wordle-solving program. I downloaded the ...
user avatar
3 votes
1 answer
86 views

Class to wrap result or exception, similar to the OneOf approach

I recently came across the OneOf<T0,...,Tn> package from mcintyre321 via a video by Nick Chapsas, which presents the idea of holding exception types to be ...
user avatar
  • 1,329
3 votes
1 answer
197 views

Generic Scanner(System.in) Parsing

Often end up using a Scanner to grab some simple input and often when dealing with Number input it can result in a lot of little ...
user avatar
2 votes
1 answer
93 views

C++ exception class for error reporting, compatible with C++98 through C++20 (ver 2)

This question contains revised code from the question What should a C++ error reporting exception class have to be portable across language versions?. I summarize what is different from that code at ...
user avatar
8 votes
2 answers
140 views

What should a C++ error reporting exception class have to be portable across language versions? (ver 1)

Link to revised (ver 2) question This question contains the first version of the code for the task explained below. The revised version is at C++ exception class for error reporting, compatible with ...
user avatar
2 votes
1 answer
51 views

C++ exception handling

I'm getting throw exception and need your review The main function bellow trying to allocate memory several times and then throw the exception on the upper level. ...
user avatar
1 vote
0 answers
72 views

How to catch exceptions in test code?(Python 3.8) [closed]

I have a script that includes some independent tests that run together (not parallelly). The tests include calls for some libraries that might raise exceptions (which indicate of a failure in the test)...
user avatar
  • 29
3 votes
2 answers
136 views

"Guess a random letter" game with command line interface

The code below if launched on the command line is a simple guessing game. A random character 'a', 'b' or 'c' is chosen, and the user is prompted until they guess correctly. It's arguable that invalid ...
user avatar
  • 218
6 votes
1 answer
203 views

Handling errors in potentially incomplete responses

I am using the library geoip2 to get Geolocation of many IP adderesses ...
user avatar
5 votes
2 answers
1k views

C++ custom exception class

I am wondering, how can I improve this simple MissingResource exception class? I am using it in my simple game. ...
user avatar
  • 209
1 vote
1 answer
72 views

Handling multiple try-catches in a for loop

Good day! I would like to know if this is possible to be refactored into a cleaner code. The reason I'm doing it like this is to catch the column that the error appeared on and then potentially output ...
user avatar
4 votes
2 answers
202 views

Sanity check a simple RPG character

I'm writing an assistant for the tabletop RPG Pathfinder in Java. I intend to use the MVVM pattern using JavaFX, possibly through mvvmFX. Before I go into the V-VM phase, I have built a first ...
user avatar
  • 310
2 votes
1 answer
70 views

c++ new-handler

I had just put together my first public project: simple(sane) new-handler for c++. It allocates some reserved memory on start up, then releases it piece by piece. It may also raise a signal when each ...
user avatar
  • 168
4 votes
2 answers
230 views

Reader for graph-file with ugly return and questionable use of streams

I wrote a class that contains a static method that reads in files from NetworkRepository and converts them into a list of integer-arrays, each representing an edge. The file format from ...
user avatar
2 votes
0 answers
1k views

Powershell custom exception class

I am trying to get my head around exceptions, and implement exception handling that ultimately gets logged, since my code runs as a remote job and reviewing a txt log is the best means of reviewing ...
user avatar
4 votes
1 answer
106 views

Custom exception for each invalid input value

I have backend project in which there's own "parent-to-all exception" exists, something like this (also I have InvalidArgumentException derived from this exception): ...
user avatar
  • 141
-2 votes
1 answer
68 views

Is it good practice to use try catch only for a part of the code [closed]

When I submit the form, I need to validate the input data from an HTML form field, which comes from the user who submitted the data. So inside the Page_Load event, ...
user avatar
  • 97
11 votes
2 answers
342 views

Self-inflicted killing utility

If you need to kill the same process that you're in (for testing purposes or whatever) this code will do it. A definitive, quick, unmerciful dead of the current Java program/app. Not a System.exit(0) ...
user avatar
1 vote
1 answer
46 views

Handling errors in an input based program

I wrote a program which creates a svg-group that contains several arranged rectangles with passages inbetween to reach all of the rectangles inside of an area selected by the user. Each rectangle ...
user avatar
0 votes
0 answers
33 views

Error handling in Go

I have a function which returns an error. I would like to handle this error on the caller function, so I need to know the reason of the error in the caller function. Below there is my solution, but I ...
user avatar
  • 772
0 votes
1 answer
92 views

One try with multiple catch blocks vs nested try

I am creating program which will parse .csv file and I am using FileReader and Scanner classes from java API. ...
user avatar
  • 3
2 votes
1 answer
833 views

Employee database

To keep in practice with good techniques of java programming, I've decided to write a database. All it does it stores employees, allows users that are logged in to get/set employees, and has a login ...
user avatar
  • 9,476
4 votes
2 answers
1k views

Compiling and throwing simple dynamic exceptions at runtime for JVM

I've been using my Dynamic Exception with C# for quite some time already and it saved me a lot of time. This means, I don't have to create a new exception ...
user avatar
  • 43.8k
5 votes
1 answer
168 views

"Detailed" exception class hierarchy

I'm designing an modular exception class hierarchy to use in various projects. I intend to inherit from std::exception in order to be maximally compatible with any ...
user avatar
  • 625
8 votes
2 answers
2k views

See if a specific resource exists in a Kubernetes namespace

I want to have a function that checks to see if a certain resource (deployment, job, cronjob etc) exist in a namespace. Using the Kubernetes Python client, I can create a boolean function (using ...
user avatar
5 votes
1 answer
111 views

Game asset manager

I've been using Monogame for hobby game development for the last year now. My game assets aren't large so I usually load them all on startup. I would have a static AssetManager class with a ...
user avatar
1 vote
1 answer
59 views

Exception handling with null check in java

...
user avatar
5 votes
2 answers
4k views

Custom C++ exception class with stack trace generation

I wanted to implement my own runtime error class in C++, that could provide more meaningful information on where the error occurred than std::runtime_error does. I ...
user avatar
  • 225
0 votes
1 answer
73 views

Using a wrapper on a primitive as a generic for an interface used for Java lambda

I apologize for that title, lol. I have a Java method that I'm writing where I want to be able to pass in an array of Objects and two interfaces that will be used for lambda expressions that specify ...
user avatar
  • 113
4 votes
2 answers
172 views

Automatic exception wrapper in java

There's a lot of place in my code where I need to do something like this ...
user avatar
  • 151
5 votes
1 answer
4k views

C++ Read istream into string with exceptions

Did I cover all the bases? Can this be improved (best practice)? Edit... I've come up with some improvements. When I tried edit the code, the software complained about too much code and too little ...
user avatar
1 vote
0 answers
56 views

Exception handling with recurrency

I writing application that collect job offers from few websites and tries to apply for each joboffer using implementation of this interface for each website: ...
user avatar
  • 11
2 votes
1 answer
104 views

Class hierarchy for informative exceptions in ASP.NET core

I have a base class called ExceptionPlus(please suggest a better name). Which is being inherited by multiple child class like BusinessNotFoundException, ArgumentInvalidException etc. My question is ...
user avatar
  • 121
2 votes
1 answer
84 views

Getting single element or throwing one of two exceptions

Sometimes I need to get a single thing from a collection but I'm not very happy with the Single extension. It does not differentiate between empty and more than one ...
user avatar
  • 43.8k
3 votes
1 answer
214 views

Custom exceptions for validating movie information

I wrote my first application about custom exceptions and catching them. Here is the GitHub link. I Have 3 types of custom exceptions: TimeException (validate time: hours, minutes) MovieException (...
user avatar
  • 33
6 votes
1 answer
6k views

Creating data objects dynamically at runtime from an interface

Sometimes when I write objects for holding data (not real DTOs, no serialization involved) I also create an interface for it. The class that implements it can also perform some null checks. I don't ...
user avatar
  • 43.8k
2 votes
3 answers
2k views

Compiling and throwing simple dynamic exceptions at runtime

I often need a simple exception with a meaningful name and some helpful message which usually just looks like this one: ...
user avatar
  • 43.8k
7 votes
2 answers
1k views

Validation for a CQS system that throws an exception

I've been reading that exceptions should only be for something "exceptional" and not used to control the flow of a program. However, with a CQS implementation, this seems impossible unless I start ...
user avatar
1 vote
1 answer
154 views

Is it a valid use case of using java.util.MissingResourceException?

I have a factory method that returns an Object based on a argument passed to it : ...
user avatar
3 votes
1 answer
10k views

C++ custom exception design

I have a custom exception hierarchy in C++ to detect unexpected cases in a library I am implementing. The base exception class inherits from std::exception and all ...
user avatar
  • 233
10 votes
3 answers
6k views

Prompting for two integers and dividing, using exceptions to handle divide-by-zero errors

I'm trying to learn exception handling in C++. I wanted to read two integers and divide them and print them. The code should throw an exception when the second integer is zero, ask the user to re-...
user avatar
  • 121
6 votes
1 answer
2k views

Generating unique ID of an exception

For classifying error reports, I need to generate an ID from an exception. That ID should be (more or less) unique a short alpha numeric string equal for equivalent exceptions (even on different ...
user avatar
  • 8,498
5 votes
3 answers
7k views

Custom exception for string that is too long

This is my first time working with Java exceptions. I have made a program that works to specifications, but I am wondering if there is anything I've done which is unconventional or not recommended. ...
user avatar
4 votes
2 answers
1k views

ExceptionPrettifier for prettier exception strings

I've been refining my previous idea for pretty exception strings and made the following changes: Exceptions can be ordered. Prints all properties including Data. ...
user avatar
  • 43.8k
1 vote
2 answers
4k views

Hackerrank Inherited Code

I'm back at it again with an Hackerrank challenge-Inherited Code . I just learnt exception and I thought it will be a great idea to get a second opinion on my implemented ...
user avatar
  • 2,420
5 votes
2 answers
1k views

Catching exception inside model

Is it normal to catch exception in concept of MVVM inside model? Or how should it be? How to improve this code? This is simple application that allows user to drop .pfx certificate on the label. <...
user avatar
  • 275
2 votes
0 answers
209 views

Checking authentication status by looking for a cookie

I'm an Android newbie. I have this function in my code: ...
user avatar
3 votes
1 answer
98 views

Command sequence executor with error handling

I've recently learned that as a Java developer my methods throw exceptions way too often, even when the reason for throwing is related to a business rule, when returning an error code instead could ...
user avatar
  • 195
3 votes
1 answer
200 views

Lightweight C Exception Library

...
user avatar
1 vote
1 answer
4k views

Custom Exception.ToString() formatter

I find the default Exception.ToString() formattig very difficult to read especially if there are inner exceptions involved. I guess everyone knows how it looks: <...
user avatar
  • 43.8k