exception-handling

What to log when an exception occurs?

public void EatDinner(string appetizer, string mainCourse, string dessert) { try { // Code } catch (Exception ex) { Logger.Log("Error in EatDinner", ex); return; } } When an exception occurs in a specific method, what should I be logging? I see a lot of the above in the code I work with. In these...

Suppress unhandled exception dialog?

I'm handling all of my unhanded exception in the code but whenever one happens (not during debugging) I get my error window and as soon as it closes "Unhandled application exception has occurred in your application" window pops up. How do I suppress it? PS : I am not using ASP.NET , I'm using Windows Forms ...

How to catch exception on RollBack

What is the best way to implement error handling for a SqlTransaction RollBack that already exists within a catch clause? My code is roughly like this: using (SqlConnection objSqlConn = new SqlConnection(connStr)) { objSqlConn.Open(); using (SqlTransaction objSqlTrans = objSqlConn.BeginTransaction()) { try { // code ...

.NET List of Thrown Exceptions

I know that Java enforce the programmer to list all exceptions that will be thrown by the method, and thus creating an easy way of listing all possible thrown exception for the user of code. .NET on the other hand has no such feature, and all we're left with is the API documentation or XML documentation where the exceptions are sometime...

Cost of creating exception compared to cost of logging it

Hello, Just wonder how much cost to raise a java exception (or to call native fillInStackTrace() of Throwable) compared to what it cost to log it with log4j (in a file, with production hard drive)... Asking myself, when exceptions are raised, does it worth to often log them even if they are not necessary significant... (i work in a hig...

Confused by this PHP Exception try..catch nesting

Hello. I'm confused by the following code: class MyException extends Exception {} class AnotherException extends MyException {} class Foo { public function something() { print "throwing AnotherException\n"; throw new AnotherException(); } public function somethingElse() { print "throwing MyException\n"; throw new ...

What does try do in java?

What does try do in java? ...

What to Return? Error String, Bool with Error String Out, or Void with Exception

I spend most of my time in C# and am trying to figure out which is the best practice for handling an exception and cleanly return an error message from a called method back to the calling method. For example, here is some ActiveDirectory authentication code. Please imagine this Method as part of a Class (and not just a standalone funct...

I've caught an exception!! Now what?

Hi folks, I've started using try catch blocks (bit late i know!) but now im not sure what to do with the exception once i've caught it. What do people usually do here? -- Jonesy Try connection.Open() Dim sqlCmd As New SqlCommand("do some SQL", connection) Dim sqlDa As New SqlDataAdapter(sqlCmd) ...

Is the "message" of an exception culturally independent?

In an application I'm developing, I have the need to handle a socket-timeout differently from a general socket exception. The problem is that many different issues result in a SocketException and I need to know what the cause was. There is no inner exception reported, so the only information I have to work with is the message: "A conn...

Is there any reason to throw a DivideByZeroException?

Are there any cases when it's a good idea to throw errors that can be avoided? I'm thinking specifically of the DivideByZeroException and ArgumentNullException For example: double numerator = 10; double denominator = getDenominator(); if( denominator == 0 ){ throw new DivideByZeroException("You can't divide by Zero!"); } Are the...

Programming Concepts: What should be done when an exception is thrown?

This does not really apply to any language specifically, but if it matters I am using VB.NET in Visual Studio 2008. I can't seem to find anything really that useful using Google about this topic, but I was wondering what is common practice when an exception is thrown and caught but since it has been thrown the application cannot continu...

A couple of questions on exceptions/flow control and the application of custom exceptions

1) Custom exceptions can help make your intentions clear. How can this be? The intention is to handle or log the exception, regardless of whether the type is built-in or custom. The main reason I use custom exceptions is to not use one exception type to cover the same problem in different contexts (eg parameter is null in system code w...

Exception hierarchy in java

As Error and Exception are subclass of throwable class, we can throw any error, runtime ex and other ex. Also we can catch any of these type. Why do we usually catch only checked Exception? Can somebody provide me good links for exception with examples? ...

Exception catching from base of the class

I have a base class, and I would like to catch all exceptions of the derived class within the base class, is this possible? You won't know what the methods are from the derived class. ...

What is best strategy to handle exceptions & errors in Rails?

Hello. I was wondering if people would share their best practices / strategies on handling exceptions & errors. Now I'm not asking when to throw an exception ( it has been throroughly answered here: SO: When to throw an Exception) . And I'm not using this for my application flow - but there are legitimate exceptions that happen all the...

Is there a reason Image.FromFile throws an OutOfMemoryException for an invalid image format?

I am writing code that catches this OutOfMemoryException and throws a new, more intuitive exception: /// ... /// <exception cref="FormatException">The file does not have a valid image format.</exception> public static Image OpenImage( string filename ) { try { return Image.FromFile( filename, ); } catch( OutOfMe...

Unhandled Exception in c#

Hello i am currently trying to run a web crawler through the terminal. it compiles fine and the debug does not find any errors, however i get the following error which i do not understand. any ideas on how to get rid of this error would be much appreciated Unhandled Exception: System.ArgumentOutOfRangeException: startIndex + length > th...

Capturing unhandled exceptions in .Net 2.0. Wrong event called.

Hello, I'm investigating a bit about how the unhandled exceptions are managed in .Net and I'm getting unexpected results that I would like to share with you to see what do you think about. The first one is pretty simple to see. I wrote this code to do the test, just a button that throws an Exception on the same thread that created the ...

Exception handling in R

Does anyone have examples/tutorials of exception handling in R? The official documentation is very terse. ...