exception-handling

Learning about Try-Catch blocks

I'm a Java beginner so please bear with me :P static int load = 100; static int greet; public void loadDeduct(int cLoad, int c){ int balance; balance = cLoad - 7; System.out.println("Your balance: " + balance); } public void loadDeduct(int tLoad){ int balance; balance = tLoad - 1; System.out.println("Your balan...

Exception handling differences questions

It is possible to catch an exception and throw a new exception which wraps the first exception as an inner exception: http://msdn.microsoft.com/en-us/library/system.exception.innerexception(VS.71).aspx Also, if I call a function and it throws a certain error, but I catch it, will the calling code's catch handler execute? If so, and it ...

PHP: exceptions vs errors?

Maybe I'm missing it somewhere in the PHP manual, but what exactly is the difference between an error and an exception? The only difference that I can see is that errors and exceptions are handled differently. But what causes an exception and what causes an error? ...

ASP.NET Database Error Trapping

I am curious as to how people trap certain database errors in .NET, particulary foreign key or unique index violations. Coming from a Classic ASP/VB background, my first inclination is to test the error number to then create a friendly message to the user that something is wrong. However, I would think that in the .NET world, there wou...

Code reuse in exception handling

I'm developing a C api for some functionality written in C++ and I want to make sure that no exceptions are propagated out of any of the exported C functions. The simple way to do it is making sure each exported function is contained in a: try { // Do the actual code } catch (...) { return ERROR_UNHANDLED_EXCEPTION; } Let's say...

Proper catching of specific exceptions through web service

I am currently using a C# .NET Service in our client program. As part of the server design, several custom made exceptions are thrown to indicate specific errors (as in any normal desktop program). The problem is that the Web Service catches these errors and serializes them into a FaultException, with the actual exception (like NoRoomsA...

Why String.indexOf do not use exception but return -1 when substring not found?

Why String.indexOf do not use exception but return -1 when substring not found? The purpose of this question is: when we start custom exception. I believe avoid the need to return special error code is right design path. What's your opinion? ...

JBoss AOP syntax to intercept exceptions

I'm familiar with the AspectJ syntax for intercepting Exceptions using the "handler" designator, but I'm trying to get the same item working with JBossAOP. Would anyone know how to catch all exception throws so I can log them using JBossAOP? Thanks! ...

Exception handling in Ajax Calls.

I have an application utilizing lots of AJAX requests (different actions are triggered via XHR requests). Some of those calls may result in exceptions. Each time I have to display an error message to the user. How can I organize error handling in this case? ...

Why catch and rethrow Exception in C#?

Hi, Folks, forgive me, I'm pretty much a raw prawn when it comes to C#, and .NET generally... though I've been a professional programmer for 10 years. I'm looking at this article: http://www.codeproject.com/KB/cs/datatransferobject.aspx on Serializable DTO's. The article includes this piece of code: public static string SerializeDTO(...

Why is swallowing InterruptedException ok for subclasses of Thread ?

In Brian Goetz's article on how to handle InterruptedException, one paragraph stands out: The one time it's acceptable to swallow an interrupt is when you know the thread is about to exit. This scenario only occurs when the class calling the interruptible method is part of a Thread, not a Runnable. I don't get this. Is the reason ...

Exceptions and memory

When an exception is thrown or encountered: void ThrowException() { try { throw new Exception("Error"); } catch { } } is it & how is it disposed from memory? and how does the above code differ from the below code in respect of the disposal from memory of the Exception object? void ThrowException() { ...

Is it good to catch a more general type of Exception?

If we are to catch specific forms of IOException, or any other kind as a matter of fact, and we only try and catch a couple (and define definitive outputs for them) say FileNotFoundException ZipException should we always trail it off and cover all bases with a catch(IOException e){ e.printStackTrace(); } and then possibly go ev...

Adding more details to exception handling with Enterprise Library

I am using Enterprise Library 4.x for my exception handling logging (ASP.NET application). Here is the EntLib method I am calling: ExceptionPolicy.HandleException(ex, exceptionPolicy.ToString()); How can I add a bit more details to the exception, like current request url, current user name, etc.? I know I could wrap it in my except...

hasattr() vs try-except block to deal with non-existent attributes

if hasattr(obj, 'attribute'): # do somthing vs try: # access obj.attribute except AttributeError, e: # deal with AttributeError Which should be preferred and why? ...

Are there any frameworks or libraries for logging errors remotely with .Net?

I'd like all of my .Net applications to be able to log unhandled exceptions via the internet when a connection is available. Are there any libraries people use for this purpose (preferably free/open source)? ...

Ensuring all exceptions are considered when using PHP

I've used exceptions in Java and like the way it won't let you call a method unless you catch or throw the exceptions that it might throw. I'm looking for something similar in PHP. I realise PHP is more dynamic than Java, and doesn't even let you define the exceptions that it throws, but what is the closest I can get? We document our m...

Why is UnhandledExceptionEventArgs.ExceptionObject an object and not an Exception?

Why is UnhandledExceptionEventArgs.ExceptionObject an object and not an Exception? I am attaching to AppDomain.UnhandledException. I would like to cast UnhandledExceptionEventArgs.ExceptionObject to an Exeption and interogate it. And with this in mind will it ever be null? The MSDN documentation is not exatly useful http://msdn.mic...

Consuming services that consume other services.

What is the best way to confirm that these consumed services are actually up and running before I actually try to invoke its operation contracts? I want to do this so that I can gracefully display some message to the customer to give him/her a more pleasant user experience. Thanks. ...

Exception handling in a client - server architecture

I have a project consisting of a windows client (approx. 150 users), a webservice and some windows services. All together working in an intranet and build using C# .NET 3.5. Now I want to log exceptions in a central database and manage them (watch top 10, ticket system, etc.) via a web application. I thought about using and expanding EL...