exception-handling

catching exception-general doubts

I am learnig CSharp.I have some doubts in handling exceptions.Kindly guide me to improve my coding knowledge. Suppose i construct a code segment : try { SomeWork(); return success; } catch (someException ex) { throw new ExceptionDetails(ex); return failure; } catch(AnotherExcep...

What errors / exceptions trigger Windows Error Reporting?

When running a Delphi application outside the debugger most exceptions that occur seem to be silently ignored (like an access violation). Sometimes however there appears the Windows error reporting dialog (send or not send, you probably know what I mean). What exactly does this mean? What errors trigger this behaviour? Additional info: ...

Catch Block Choices

I am reading C# article.It suggests that At the end of the catch block, you have three choices: • Re-throw the same exception, notifying code higher up in the call stack of the exception. • Throw a different exception, giving richer exception information to code higher up in the call stack. • Let the thread fall out of the botto...

Will CLR handle both CLS-Complaint and non-CLS complaint exceptions?

Just for my clarification : Can i throw both CLS-Complaint and non-CLS complaint exceptions in .NET Framework ?.I am using C# 3.0. When i catch exception catch(Exception ex) { } Will it catch only CLS-Complaint exceptions?. What is the use of RuntimeWrappedException class (can i have a simple example?). ...

Possible syntax for multi-type catch blocks in C#?

Here are two previous questions regarding this topic: Catch multiple Exceptions at once? More Elegant Exception Handling Than Multiple Catch Blocks? I was working today and thought this might be an appropriate syntax should this feature ever be added to the C# language. Anyone have any opinions about it? The type of e must be a base...

spring mvc: detect if an exception has been thrown while loading the context

I have a spring mvc application and we run tests with it using jetty. Sometimes the loading of the context totally fails, because bad xml or because Class Not Found exception or because a bean throws an exception in the constructor, setter or init method. In such a case I would like to to stop the application with System.exit(1) or tak...

Using uncaughtExceptionHandler effectively.

I got to know about this Java 1.5 capability recently and I developed a sample code to use this. My objective is to restart the thread when it gets dead due to an uncaught exception. public class ThreadManager { public static void main(String[] args) throws InterruptedException { startThread(); } public static void st...

How to avoid "Response.Redirect cannot be called in a Page callback"

I'm cleaning up some legacy framework code and a huge amount of it is simply coding by exception. No values are checked to see if they are null, and as a result, copious amounts of exceptions are thrown and caught. I've got most of them cleaned up, however, There are a few error / login / security related framework methods that are do...

BizTalk - Catch EndPoint Not found Exception

The WCF service to which my send & receive ports are configured, is not available; thus I am getting an EndPoint not found exception. How do I catch this exception in the middle of my orcehstration and flow towards a clean exit from the orchestration? I should be able to capture the detail and invoke a class lib (through Expression shape...

Handle exceptions with WPF and MVVM

I am attempting to build an application using WPF and the MVVM pattern. I have my Views being populated from my ViewModel purely through databinding. I want to have a central place to handle all exceptions which occur in my application so I can notify the user and log the error appropriately. I know about Dispatcher.UnhandledExcepti...

which is a better practice at exception handling?

if I have a specific exception that I expect when it is going to occur; and to handle it for example I chose to display an error message upon its occurance, which would be better to do, and why? Explanatory code: try { string result = dictionary[key]; } catch (KeyNotFoundException e) { //display error } or: if(!dictionary...

Unchecked Exceptions thrown in a GUI Application

We know that unchecked exceptions are to use in case of violation of the contract of a method. If the application is running in a console, the exception will appear in the console window, along with its stack trace. This is true even for GUI application (say written in Swing) invoked from a console and console is running in the backgroun...

Java: Global Exception Handler

Hello, Is there a way to make a global exception-handler in Java. I want to use like this: "When an exception is thrown somewhere in the WHOLE program, exit." The handler may not catch exceptions thrown in a try-catch body. Martijn ...

How to catch exception from CloseHandle()

As of the MSDN spec, CloseHandle throws an Exception if an invalid handle is passed to it when it runs under a debugger. Since I want to have clean code, I've inserted some code to catch it. However, it doesn't work, the exception gets uncaught. #include <windows.h> #include <tchar.h> #include <exception> /* omitted code */ CloseHandle...

Can I avoid exceptions in C#, continuing code execution?

I have the following C# code. Whenever an exception is caught, say at line 1, I am never able to reach other lines (2, 3, 4, etc). try { line1 line2 ... } catch (Exception ex) { ... } Is it possible, in C#, to say that if line 1 generates an exception, just continue on to the other lines (2, 3, 4, etc)? ...

Why do I get an "Uncaught exception" error?

I have the following PHP code: foreach (...) { try { $Object = MyDataMapper::getById(123); if (!$Object->propertyIsTrue()) { continue; } } catch (Exception $e) { continue; } } MyDataMapper::getById() will throw an Exception if a database record is not found. Here is the definition of that method: public...

ASP.NET MVC exception handling

Is it OK to catch my exceptions in the controller's actions? Is there any better way of doing it? I'm actually catching my exceptions in the controller and using TempData to show a message to the user, but I have a weird feeling about this approach. I've been browsing around but I haven't found anything that suits me. ...

Nicely format an exception into a string

I'd like to build a nicely formatted string of a exception for logging. Doing this from silverlight so options like nlog (not there yet), log4net aren't an option. Anyone seen the code to build up something like: ExceptionType: xxxx Message: xxxx StackTrace: XXX InnerException ExceptionType: xxxx Message: xxxx StackTrace: ...

Is there any way to identify if it is a test or not (.NET)?

I want that my application catches the exceptions and e-mail them when running in production, but when I am running my MSTest unit tests I want it to throw the exceptions, so I can debug. My current code always e-mails the exceptions. There is any way to know if the current process was invoked by the unit tests? One way I can think is t...

Difference: std::runtime_error vs std::exception()

What is the difference between std::runtime_error and std::exception? What is the appropriate use for each? Why are they different in the first place? ...