Questions tagged [exception]

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

3
votes
1answer
71 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 ...
4
votes
2answers
798 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 ...
5
votes
1answer
67 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 ...
1
vote
0answers
62 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 ...
5
votes
1answer
64 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 ...
1
vote
1answer
49 views

Exception handling with null check in java

...
5
votes
2answers
1k 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 ...
0
votes
1answer
54 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 ...
4
votes
2answers
109 views

Automatic exception wrapper in java

There's a lot of place in my code where I need to do something like this ...
5
votes
1answer
1k 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 ...
1
vote
0answers
52 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: ...
2
votes
1answer
85 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 ...
2
votes
1answer
69 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 ...
3
votes
1answer
149 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 (...
2
votes
1answer
3k 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 ...
2
votes
3answers
508 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: ...
7
votes
2answers
567 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 ...
1
vote
1answer
92 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 : ...
3
votes
1answer
5k 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 ...
10
votes
3answers
5k 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-...
5
votes
1answer
919 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 ...
5
votes
3answers
4k 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. ...
4
votes
2answers
606 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. ...
1
vote
2answers
1k 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 ...
4
votes
2answers
522 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. <...
2
votes
0answers
185 views

Checking authentication status by looking for a cookie

I'm an Android newbie. I have this function in my code: ...
3
votes
1answer
81 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 ...
3
votes
1answer
146 views

Lightweight C Exception Library

...
1
vote
1answer
3k 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: <...
2
votes
4answers
374 views

Throwing exceptions if there is not exactly one box retrieved

(Note: this is originally posted as this SO question ) I'm trying to refactor the error logging and exception throwing into a method. Original code: ...
0
votes
1answer
413 views

Count check before Linq Single() call

Should I check Count before Linq Single() call if I expect only one element? ...
2
votes
1answer
166 views

Extended exception for network errors in Python

I need a custom exception for network errors that holds a related exception and more than one URL (the first one as the used service has its URL but it indirectly calls other URLs), so I wrote this: <...
1
vote
1answer
105 views

Python exception handling class - Getting as much details printed

I'm trying to write a Exception Handling class in Python so that I can re-use. If you have any ideas on how I can improve this to output more detailed information I would appreciate it: ...
4
votes
2answers
4k views

DAO to create, update, and delete a project

I'm trying to write my first "complex" program in Java. So far, I created a local H2 database but I'm not sure about the quality of my code (I'm newbie in Java) because I don't know how I can deal ...
3
votes
1answer
331 views

Using a Boolean method that never returns “false” to check user permissions

I need to check that a user is allowed to save/retrieve contacts to/from the database by calling a web service, and return an HTTP403 with an explanation if it is not the case. So for the sake of ...
1
vote
1answer
47 views

Pretty handling FileNotFoundException

I have got a piece of code that initialize Scanner in two possible ways: no argument constructor creates Scanner that uses stdIO (System.in) as source contructor with String, which creates Scanner, ...
2
votes
1answer
633 views

Retrieving access token from SharedPreference

Here is code that retrieves an access token from SharedPreference. ...
4
votes
1answer
6k views

AggregateException handling

How do you handle AggregateException? It is really useful in many TPL or business scenarios, but handling is a real pain. I defined the following three extensions ...
0
votes
1answer
230 views

Custom Exceptions based off the Visual Studio snippet

I'm creating my own application exception types so I could catch them higher in the call stack and take specific action. I'm looking to get feedback on the latest exception I've written for two ...
1
vote
1answer
938 views

Function to validate parameter and throw exception when invalid

I've asked a question receiving excessive (in a good sense) feedback. After I've incorporated it into the code, it changed substantially and I felt that I'd need opinion on the new version. Posting ...
5
votes
2answers
637 views

“Better” Exception with autogenerated message

Because I don't like writing the same useless exeption messages all the time ;-) I thought I create a better exception that would make this for me. This is what I came up with: ...
4
votes
2answers
350 views

Throw an exception which contains a nested set of previous exceptions

I have a set of domain objects which try to find a solution to a problem. The top level object has an algorithm which splits up the problem and delegates it to lower level objects, which in turn do ...
3
votes
1answer
961 views

Custom error/fatal error and exception handler in PHP

Introduction I wrote three functions that aims to log errors and exceptions as well as show a user a generic error page. Would appreciate some feedback on it with regards to the PSR standards and if ...
7
votes
1answer
1k views

Cancellable futures, interaction with throwing destructors

I'm reinventing std::future from scratch (for an upcoming talk). I'd like to incorporate as many of the latest and most likely-to-succeed proposals as possible, and ...
1
vote
1answer
279 views

Working with Exceptions Exercise

The task: There is an AccountManager that makes transfers. It receives 2 arrays of the same size: accounts and sums. They need to be transferred to the accounts ...
2
votes
2answers
7k views

Parsing double from string

I'm trying to parse Double from String in Java. The string input is not necessarily a number, any non number input should be ...
7
votes
2answers
102 views

A closed exception system

I am working on yet another toy project that I named SGL (for "Standard Generic Library" since it mimics some features of C++'s STL as well as a few more utilities from the C++ standard library). ...
8
votes
4answers
536 views

C# PasswordService class

I am new to C# and develop a configurable PasswordService class. As the code works the next step is to improve the code. Right now there are the following options: ...
1
vote
3answers
36 views

Managing batch runs of Fortran programs

I have a program which basically manages batch runs of some underlying Fortran programs, and at the end, I want to move all the related files into a different directory. At the moment, there is ...
2
votes
0answers
68 views

Extending Exceptions with module-specific prefix, intended for parsing error reporting [closed]

For one of my [WIP] project, I extended the dictionary class a lot with specific handlers, as such I determined that I wanted KeyError and ...