An exception is a rarely occurring (exceptional!) condition that requires deviation from the program's normal flow.
11
votes
3answers
1k 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
122 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
329 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. ...
2
votes
2answers
111 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
122 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 ...
3
votes
2answers
75 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
80 views
Checking authentication status by looking for a cookie
I'm an Android newbie. I have this function in my code:
...
3
votes
1answer
61 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
88 views
1
vote
1answer
335 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
67 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
110 views
Count check before Linq Single() call
Should I check Count before Linq Single() call if I expect only one element?
...
2
votes
1answer
122 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
41 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
413 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
117 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
39 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
61 views
Retrieving access token from SharedPreference
Here is code that retrieves an access token from SharedPreference.
...
3
votes
1answer
297 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
89 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
90 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
220 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
129 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
514 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
225 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
89 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 ...
1
vote
2answers
491 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
90 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
483 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
33 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 ...
3
votes
0answers
61 views
Extending Exceptions with module-specific prefix, intended for parsing error reporting
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 ...
8
votes
2answers
757 views
Customized Exception
I am building my "base exception to end all base exceptions" class in C# and was looking for some opinions on my implementations so far. Ideally my usage of integrated Rethrow, Throw, and ThrowFatal ...
2
votes
1answer
2k views
Checking if a directory exists in FTP without relying on exception handling
I've written a method to check if a directory already exists on an FTP server. The only way I could see to make this work was to return a different result from the method if an exception is thrown - ...
1
vote
2answers
80 views
Simple interface and class for holding text to be analyzed
I am making a sentiment analysis library targeted first at social media text (like Twitter) and then I will expand it for more general use.
For the first step I am making a simple interface and a ...
3
votes
3answers
12k views
Use of Exception to log execution stack trace
I've been back and forth with a colleague over the use of Throwable.fillInStackTrace. This Log class is meant to wrap the Simple ...
3
votes
2answers
2k views
Guard statement extension methods for common object guards
I wrote a couple of extension methods for common guard statements I write a lot. These are extension methods for Object, and allow me to quickly guard against common scenarios.
I'm using .Net 3.5 (...
5
votes
2answers
939 views
Simple factorial program using recursion
Two concepts I realized I needed to understand and use more are recursion and Exceptions. Thus, I combined both in the following program. Although it began with a focus on using recursion it became ...
2
votes
2answers
429 views
“Nice Angles” - Code Eval challenge
Out of fun, I solved "Nice Angles" challenge on CodeEval in C# 4.0:
CHALLENGE DESCRIPTION:
Write a program that outputs the value of angle, reducing its
fractional part to minutes and ...
3
votes
2answers
71 views
4
votes
2answers
440 views
Cleaning up file resources in a DRY manner
I've written a function that generates a report, and then sends it as an attachment to an email. I don't want to clutter the function with a lot of calls to close up the filesystem, if there was an ...
3
votes
2answers
717 views
Custom exit with only some exceptions in Python
I want to define an exit code for some exceptions and some exceptions only. I want that the only input is that dictionary with the definition.
...
6
votes
3answers
6k views
Throwing exceptions when validation fails
When I want to check the validity of an attendance being entered into the system, I perform following action.
AttendancePresenter Class
...
5
votes
2answers
3k views
Storing a message from a queue
I am doing a code review and I have encountered a class in an application that is throwing an exception in the constructor:
...
3
votes
1answer
42 views
Good approach to raise an exception
I have class House and module Lockable. Locking and unlocking House should reflect the real ...
10
votes
1answer
2k views
Unhandled Exception handler that captures a screenshot
So, whether you're still in the development stages or your app is already on the app store, you always hope your app isn't crashing. But if it is, you want to be sure you've got good crash reports, ...
15
votes
2answers
2k views
Using finally with return statement or not
I was wondering if it is the proper way to always put the return statement of a function with a try-catch clause in the finally ...
1
vote
1answer
276 views
How to add exceptions in a class that reads a config file?
I am using Boost for reading a config file that is in the .json format. I am using a class to do this and I am calling exit(message) in case of bad values or ...
2
votes
2answers
273 views
Python and Exception Handling IOError [closed]
I'm trying to work with exception handling by displaying "No Such File" when the file doesn't exist. I need to use a try statement.
...
5
votes
2answers
314 views
4
votes
1answer
219 views
Throw exception in favor of an error?
I've been reviewing my previous projects for the last few days. I've found that I never return an error from any of my methods. I always throw exceptions. I googled about exceptions vs errors and I ...