Skip to main content

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

Python exception for handling invalid argument types

Greetings One small problem that anyone have to tackle with in Python is handling invalid argument types ( without an automatic static type checking tool like Mypy ) One of the best methods for ...
KhodeNima's user avatar
  • 399
2 votes
3 answers
178 views

Wrap a noexcept C++ library method with a method throwing exceptions with usable explanatory strings to stay DRY

In our apps we're using a shared inhouse library which provides filesystem functions. All the functions are noexcept. In several apps i found that similar or identical error return translations are ...
ridilculous's user avatar
3 votes
1 answer
210 views

Catching the timed out Exception raised by the __init__ method of the class ftplib.FTP

Introduction I have written a Python class which uses the module ftplib. In this class I have created a private method called <...
User051209's user avatar
2 votes
2 answers
245 views

User-defined Exceptions for Stack implementation

I am learning about user-defined exceptions in python and I have tried to incorporate them in a basic python implementation of a stack. Objects of Stack class ...
Ganesh Tata's user avatar
1 vote
1 answer
161 views

Beginner Java Tic-Tac-Toe

I had a Tic Tac Toe assignment for class and the program seems to work fine but I feel like the exception/input handling could be done in a much better way. Is this a good way to approach the ...
Drosos-kal's user avatar
5 votes
1 answer
469 views

Write a simple, clean error message without a backtrace and exit on failure

I want to write on failure to either STDOUT or STDERR a clean, simple error message for the user, without the (verbose) ...
Timur Shtatland's user avatar
1 vote
3 answers
92 views

Extensible error code infrastructure

I was answering a question, Java Exception Error Enumerations Anti-pattern, on Software Engineering Stack Exchange and found myself writing up a fair bit of code. It could use a code review so I'm ...
candied_orange's user avatar
7 votes
1 answer
740 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 ...
Richard D Lawson's user avatar
3 votes
1 answer
934 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 ...
JohnLBevan's user avatar
  • 1,409
3 votes
1 answer
944 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 ...
Tim Hunter's user avatar
2 votes
1 answer
210 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 ...
Scott McPeak's user avatar
8 votes
2 answers
321 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 ...
Scott McPeak's user avatar
3 votes
1 answer
143 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. ...
Konstantin Vinogradov's user avatar
3 votes
2 answers
192 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 ...
Progrock's user avatar
  • 218
6 votes
1 answer
213 views

Handling errors in potentially incomplete responses

I am using the library geoip2 to get Geolocation of many IP adderesses ...
Ali Pardhan's user avatar
5 votes
2 answers
2k 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. ...
weno's user avatar
  • 209
1 vote
1 answer
214 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 ...
Chansters's user avatar
4 votes
2 answers
241 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 ...
Anab's user avatar
  • 385
2 votes
1 answer
101 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 ...
zzz777's user avatar
  • 178
4 votes
2 answers
238 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 ...
Moritz Groß's 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 ...
Gordon in Ukraine's user avatar
4 votes
1 answer
124 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): ...
wcobalt's user avatar
  • 141
-2 votes
1 answer
136 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, ...
Adam's user avatar
  • 97
11 votes
2 answers
350 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) ...
Oscar Besga Panel's user avatar
1 vote
1 answer
57 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 ...
IceRevenge's user avatar
0 votes
1 answer
138 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. ...
Genjik's user avatar
  • 103
2 votes
1 answer
1k 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 ...
Linny's user avatar
  • 10.4k
4 votes
2 answers
2k 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 ...
t3chb0t's user avatar
  • 44.3k
5 votes
1 answer
347 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 ...
Anakhand's user avatar
  • 645
8 votes
2 answers
4k 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 ...
user3079474's user avatar
5 votes
1 answer
188 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 ...
Matt Clegg's user avatar
1 vote
1 answer
72 views

Exception handling with null check in java

...
Hyeonseo Yang's 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 ...
Jacajack's user avatar
  • 225
0 votes
1 answer
89 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 ...
Devsman's user avatar
  • 113
4 votes
2 answers
391 views

Automatic exception wrapper in java

There's a lot of place in my code where I need to do something like this ...
Winter's user avatar
  • 151
5 votes
1 answer
5k 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 ...
Jive Dadson's user avatar
2 votes
1 answer
118 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 ...
maxspan's user avatar
  • 121
2 votes
1 answer
96 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 ...
t3chb0t's user avatar
  • 44.3k
3 votes
1 answer
253 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 (...
llooll's user avatar
  • 33
6 votes
1 answer
7k 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 ...
t3chb0t's user avatar
  • 44.3k
2 votes
3 answers
3k 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: ...
t3chb0t's user avatar
  • 44.3k
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 ...
Daniel Lorenz's user avatar
1 vote
1 answer
199 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 : ...
Innocuous's user avatar
3 votes
1 answer
11k 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 ...
ifma's user avatar
  • 233
10 votes
3 answers
7k 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-...
AccGen's 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 ...
JanDotNet's user avatar
  • 8,538
5 votes
3 answers
9k 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. ...
RandomKaryotype's user avatar
4 votes
2 answers
2k 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. ...
t3chb0t's user avatar
  • 44.3k
1 vote
3 answers
5k 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 ...
Tolani's user avatar
  • 2,463
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. <...
A191919's user avatar
  • 265