Tag Info

New answers tagged

1

Advantages, disadvantages, and limitations of your technique: • If the calling-code is to handle the checked exception you MUST add it to the throws clause of the method that contains the stream. The compiler will not force you to add it anymore, so it's easier to forget it. For example: public void test(Object p) throws IllegalAccessException { ...


7

If logging is critical to your application, then one should stop the application if logging fails. If not critical, then being somewhat defensive one could have a secondary component to handle logging failures that logs/alerts to a secondary source. But even that is not fool proof and you will have to consider what happens if the secondary logger fails ...


2

By adding some metadata to your object, either by inheriting from an abstract class that contains that data, writing a composite object, or something similar. In ASP.NET MVC 1, this would have been done by attaching a partial class to your entity (In the C# language, classes having the same name with the modifier partial in front of them are merely ...


12

When you encounter exceptions within the logger itself, you shouldn't use the logger to log its own exceptions. The reason for that is that: You may be stuck in an infinite loop. Imagine that within your logger, you have a conditional branch which wasn't tested (and generates an exception). Imagine that once the condition is met, any further reported ...


0

Synopsis: Exceptions are evidence of bad outcomes, bugs are (some of the) causes of bad outcomes. The problem (to be solved) isn't the exception, the problem is what caused the exception. Resoning: A bug is a defect in the design or implementation of a product (not limited to software). For example, not using a properly rated relay ...


1

You might legitimately raise an exception yourself, you would hopefully never introduce a bug on purpose.


0

All exceptions are not bugs. It can be a topic of debate that all bugs are exceptions or not. We can say exceptions are the events that are not part of the normal or expected flow of application. These events can be independent of how the code is written where as a bug is essentially result of bad code(like wrong calculation). Here is an example of how not ...


0

Since this question has been re-opened for a bounty, let me mention my CUJ article from 2003 entitled "An Exception or a Bug?", which seems to address exactly the OP's question. Basically, the article defines the terms "bug" and "exception" (giving examples), and proposes strategies for dealing with each. The article proposes not to "handle" bugs but ...


0

I have been pondering the same recently, and my tentative conclusion is that the mere question arises because the .NET Exception hierarchy is severely messed up. Take, for example, the lowly ArgumentNullException which might be a reasonable candidate for an exception you don't want to catch, because it tends to indicate a bug in the code rather than a ...


1

The method is named TransformNodes. In case of an empty collection as input, getting back an empty collection is natural and intuitive, and makes prefect mathematical sense. If the method was named Max and designed to return the maximum element, then it would be natural to throw NoSuchElementException on an empty collection, as the maximum of nothing makes ...


-1

Throwing multiple checked exceptions make sense when there is multiple reasonable things to do. For example lets say you have method public void doSomething(Credentials cred, Work work) throws CredentialsRequiredException, TryAgainLaterException{...} this violates pne exception rule, but makes sense. Unfortunatelly, what usuallly happens are ...


1

The reason that you would, ideally, want to only throw one type of exception is because doing otherwise likely violates the Single Responsibility and Dependency Inversion principles. Let's use an example to demonstrate. Let's say we have a method that fetches data from persistence, and that persistence is a set of files. Since we are dealing with files, we ...



Top 50 recent answers are included