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

learn more… | top users | synonyms

8
votes
4answers
870 views

Exceptions as asserts or as errors?

I'm a professional C programmer and a hobbyist Obj-C programmer (OS X). Recently I've been tempted to expand into C++, because of its very rich syntax. So far coding I haven't dealt much with ...
15
votes
3answers
650 views

How to avoid throwing vexing exceptions?

Reading Eric Lippert's article on exceptions was definitely an eye opener on how I should approach exceptions, both as the producer and as the consumer. However, I'm still struggling to define a ...
8
votes
4answers
922 views

Is rethrowing an exception leaking an abstraction?

I have an interface method that states in documentation it will throw a specific type of exception. An implementation of that method uses something that throws an exception. The internal exception ...
8
votes
2answers
377 views

How can I debug exceptions that are not easily reproducible and only occur in a production environment?

I am working on an issue where the exception only occurs in our production environment. I don't have access to these environments, nor do I know what this exception means. Looking at the error ...
38
votes
7answers
22k views

Why use try … finally without a catch clause?

The classical way to program is with try / catch but when is it appropriate to use try without catch? In Python the following appears legal and can make sense: try: #do work finally: #do ...
15
votes
6answers
34k views

Why doesn't “object reference not set to an instance of an object” tell us which object?

We're launching a system, and we sometimes get the famous exception NullReferenceException with the message Object reference not set to an instance of an object. However, in a method where we have ...
4
votes
2answers
297 views

Nulls in every type and checked exceptions in Java?

I know that null being added to every type in Java is a source of much frustration regarding the language's type system. At the same time I generally hear complaining about checked exceptions - that ...
8
votes
7answers
1k views

Use of NotImplementedException

Is it considered bad practice to throw NotImplementedException for code you haven't written yet? Possibly TODO comments would be considered safer?
3
votes
3answers
2k views

How to store exception messages

How are exception messages commonly stored? for any domain. I'm thinking about this from a maintenance standpoint. if(!Condition1) throw new Exception("Some exception"); if(!Condition2) ...
0
votes
2answers
343 views

Is it possible to prune the stacktrace returned for a custom exception in PHP

I am working on a project in PHP that does a lot of input validation and can throw different custom exception classes in various layers of the application. To make the project code easier to read, ...
2
votes
3answers
682 views

What do you think of this Exception handling practice

I'm working on a project that includes a lot of creating/manipulating and reading JSONObjects and arrays but not in a systematic way. So there is JSON code everywhere. It is ok for me except that ...
0
votes
2answers
625 views

A good substitute for ASMX web service methods, but not a general handler

The best thing I like about ASP.NET MVC, is that you can directly call a server method (called action), from the client. This is so convenient, and so straightforward, that I really like to implement ...
8
votes
9answers
785 views

Should security restrictions cause a service to return null or throw an exception?

I'm in a bit of a disagreement with a more experienced developer on this issue, and wondering what others think about it; our environment is Java, EJB 3, services, etc. The code I wrote calls a ...
12
votes
2answers
942 views

Is it more sensible to log exceptions in a catch-all or in a base exception class?

I'm in the process of refactoring a fairly large web app. One of the major issues is inconsistent error handling and I'm trying to come up with a sensible strategy. I've created a custom error ...
22
votes
9answers
8k views

Is it good practice to catch a checked exception and throw a RuntimeException?

I read some code of a colleague and found that he often catches various exceptions and then always throws a 'RuntimeException' instead. I always thought this is very bad practice. Am I wrong?
9
votes
5answers
4k views

Throwing and catching exceptions in the same function/method

I've written a function that asks a user for input until user enters a positive integer (a natural number). Somebody said I shouldn't throw and catch exceptions in my function and should let the ...
13
votes
2answers
945 views

What is a 'good number' of exceptions to implement for my library?

I've always wondered how many different exception classes I should implement and throw for various pieces of my software. My particular development is usually C++/C#/Java related, but I believe this ...
14
votes
6answers
1k views

Why not use the word bug instead of exception?

If we refer to exceptions as bugs, why not just call it a bug in the first place instead of an exception? If in the code it's called exception and as soon as it occurs it's called a bug. Then why not ...
13
votes
7answers
952 views

Do exceptions basically exist to prevent a system from crashing?

Second of all, I was wondering if anyone knew what the difference was between exceptions (in the realm of exception control flow) and Exceptions (such as used in Java). But are they there to ...
23
votes
3answers
5k views

Why are exception specifications bad?

Back in school some 10+ years ago, they were teaching you to use exception specifiers. Since my background is as one of them Torvaldish C programmers who stubbornly avoids C++ unless forced to, I only ...
2
votes
1answer
89 views

What are possible/useful implementations when extending exceptions?

I have seen a lot of exceptions - custom or integrated in the language (PHP) itself that have no differences but their class name. When extending default exceptions to use within your own code, are ...
21
votes
4answers
6k views

Why do iterators in Python raise an exception?

Here's the syntax for iterators in Java (somewhat similar syntax in C#): Iterator it = sequence.iterator(); while (it.hasNext()) { System.out.println(it.next()); } Which makes sense. Here's ...
3
votes
2answers
458 views

Why do interrupts need to be turned off when inside other interrupt code?

Simple question that will help me understand my OS class... thanks! Basically, why is it unsafe to have an interrupt within an interrupt? (or exception within exception)
3
votes
2answers
181 views

How to handle fired listeners exceptions

This is more of a design question and i was hoping to get pros and opinions on what makes sense. BACKGROUND Imagine something that holds one or more event listeners. Every now and then the thing ...
4
votes
2answers
522 views

Is there a term for the error-handling anti-pattern of discarding all available info and just returning failure?

From time to time (unfortunately way too often) I have to fix code such as this: // C++ code bool anyOldFunction(Param p) { try { ... if(some_condition_here) { handleErrorX(); return ...
7
votes
3answers
3k views

Should I use try catch in my test methods?

I am doing unit testing. I am trying to test one function. I call it from my test component. But If remote function cannot handle the exception then my tester component will also get exception, I ...
10
votes
4answers
1k views

Do you throw an argumentexception or argumentnullexception from private methods?

I was just reviewing some code I wrote a while back, and can see that I have a couple of private methods that throw argumentnullexceptions and/or argumentexceptions if there are issues with the ...
9
votes
4answers
585 views

Is exception handling a cross-cutting concern?

I don't see much of a difference between the concerns of exception handling and logging in that both are cross cutting concerns. What do you think? Shouldn't it be handled separately on its own rather ...
11
votes
3answers
1k views

How did the idea of Exception-handling emerge into programming languages? [duplicate]

Possible Duplicate: Who designed exceptions? Today if we look at any language, exception handling is almost a compulsory feature. The languages that didn't have it earlier are implementing ...
6
votes
5answers
4k views

Is it not a good practice to handle runtime exceptions in the code?

I am working on a Java application, and I see that Run time exceptions are handled in many places. For example, try { //do something }catch(NullPointerException e){ ...
21
votes
8answers
4k views

What to put in a try/catch? [duplicate]

Note on the question: this is not a duplicate, Efficient try / catch block usage? was asked after this one. The other question is the duplicate. I was wondering what was the best way to use ...
6
votes
5answers
632 views

Checked vs Unchecked vs No Exception… A best practice of contrary beliefs

There are many requirements needed for a system to properly convey and handle exceptions. There are also many options for a language to choose from to implement the concept. Requirements for ...
19
votes
13answers
3k views

Why are null references shunned while throwing exceptions is considered okay?

I don't quite understand the consistent bashing of null references by some programming language folks. What's so bad about them? If I request read access to a file that doesn't exist then I'm ...
12
votes
4answers
2k views

Good use of try catch-blocks?

I always find myself wrestling with this... trying to find the right balance between try/catching and the code not becoming this obscene mess of tabs, brackets, and exceptions being thrown back up ...
4
votes
3answers
459 views

Improving exception handling? [duplicate]

I am a newbie programmer and I recently started learning about exception handling in Java. I know what try, catch and finally blocks do, but I really need to understand how to use them well and where ...
9
votes
4answers
4k views

How to simulate events that cause exceptions to test try/catch blocks?

I understand how exceptions work and how to catch and handle them in C# but how can I simulate events that may cause an exception to ensure that it is caught correctly? For example, is it possible to ...
21
votes
2answers
1k views

Who designed exceptions?

Where did exceptions and exception handling come from? I like how .NET uses it, I like how C++ supports it (but libraries unfortunately use return code or is written in C instead). I know its pretty ...
1
vote
1answer
347 views

How does compiler handle exceptions that are implicit? Looking for design strategies

Throughout the function handleException, the exception encountered is implicit. How does the compiler handle such implicit passing of exceptions? [For e.g. in C++ methods, this pointer is passed to ...
26
votes
12answers
1k views

What are developer's problems with helpful error messages? [closed]

It continue to astounds me that, in this day and age, products that have years of use under their belt, built by teams of professionals, still to this day - fail to provide helpful error messages to ...
38
votes
4answers
2k views

How to write a good exception message

I'm currently doing a code review and one of the things I'm noticing are the number of exceptions where the exception message just seems to reiterate where the exception occurred. e.g. throw new ...
6
votes
4answers
134 views

Do you have any teamguidelines regarding exceptions?

My team recently inherited a project from a team where the amount of developers dropped so low they had to offload some work. One of the projects we inherited was a project littered with nested code, ...
2
votes
1answer
56 views

Error handling, creating time line, need help defining what aspects of the environment need tracking

For my final year project, I'm working on a script that will run your python program and provide a time line of events(so far working on assignments) and create a story of what happened(the changes in ...
11
votes
1answer
3k views

Why does Java exit with success after an uncaught exception?

Any time a Perl, Python, C++ or Tcl program halts with an unhandled exception, those language runtimes take care to register a non-zero exit code for the process. Even Eclipse-based programs return 1 ...
12
votes
6answers
2k views

What's the best way to manage error logging for exceptions?

Introduction If an error occurs on a website or system, it is of course useful to log it, and show the user a polite message with a reference code for the error. And if you have lots of systems, you ...
8
votes
5answers
572 views

How much redundancy/robustness should complex software implement?

The focus of this question: Some software performs "extra work" in order to increase the chance of a "eventually successful/satisfactory" outcome, despite one or more internal errors in the software, ...
12
votes
8answers
2k views

In Java, what are checked exceptions good for? [closed]

Java's checked exceptions have gotten some bad press over the years. A telling sign is that it's literally the only language in the world that has them (not even other JVM languages like Groovy and ...
35
votes
20answers
4k views

Is it ever ok to have an empty catch statement?

I thought about it and could not come up with an example. Why would somebody want to catch an exception and do nothing about it? Can you give an example? Maybe it is just something that should never ...
7
votes
6answers
1k views

Is throwing an exception from a property bad form?

I've always been of the mindset that properties (ie, their set/get operations) should be fast/immediate and failure-free. You should never have to try/catch around getting or setting a property. But ...
8
votes
3answers
1k views

Exceptions or Error codes

We are building a web service(SOAP, .Net) which would be talking to (mostly) native clients (windows, C++) and we are wondering what is the best way to communicate errors to the client (e.g. ...
18
votes
4answers
862 views

Using assertions versus throwing exceptions?

Often when I write a functions I want to make sure the inputs to it are valid in order to detect such errors as early as possible (I believe these are called preconditions). When a precondition fails, ...