exception-handling

How should you handle exceptions that occur below the level of the Controller in a Spring MVC web app?

Let's say you've got a Spring web app with a structure like this: com/ myapp/ controller/ model/ service/ How should you handle exceptions that occur below the level of the controller? Should you make methods in the Model and Service layers throw their exceptions up to the Controller layer? What to...

Catch REFERENCE constraint exception from SQL in C#

What will be proper way to catch exception which throw SQL server when I deleting data with Reference constraint from C# code. I want to show my users message like: "I can't delete the data because is used" , rather than of showing message like this: The DELETE statement conflicted with the REFERENCE constraint ... The conflict ccurr...

How can I handle a dialog box raised by a program I start from Perl?

I have a Perl script that calls another application I don't have control over. I use the system() to call this application. On occasion, this application generates an unhandled exception and puts up an exception dialog box that needs to be attended to. Since this is an unattended Perl script, I would like to detect this situation and han...

How to catch Errno::ECONNRESET class in "case when"?

My application (Ruby 1.9.2) may raise different exceptions, including net-connection breaks. I rescue Exception => e, then do case/when to handle them in defferent ways, but several errors go through my cases straight to else. rescue Exception => e p e.class case e.class when Errno::ECONNRESET p 1 whe...

try catch bad form?

hi there i think i sort of know the answer to this, but there are always many ways to do things (some of which are clearly wrong :) )... I have a little recursive function to find an employees manager's id. this is being used in a import script and it may be that the persons immediate manager has left (been disabled) so we need to find ...

Making a custom object to hold an exception when implementing error handling in an API

Hi, I am working on an API with several classes/methods etc. Most of the methods return objects representing things like a CPU, DVD drive, etc. We are implementing exception handling. Is it a good practise (not necessarily best...) to return an interface which all types (DVD drive, CPU, etc) derive from (this is good I know), but also ...

How to handle exceptions from C++ via SWIG to Java

We are implementing a wrapper on C++ code for exposure to Java clients. I have seen the SWIG documents about exception handling but what does this translate to in coding terms in the three layers (C++/SWIG/Java)? If anybody has working example(s) or advice, I would be grateful. ...

Print info about exception in python 2.5?

Python 2.5 won't let me use this syntax: try: code_that_raises_exception() except Exception as e: print e raise So how should I print information about an exception? Thanks EDIT: I'm writing a plugin for a program that includes kind of a pseudo python interpreter. It prints print statements but doesn't show exceptions at ...

.NET 4 Serial Port ObjectDisposedException on Windows 7 Only

This is a problem I used to have all the time with the serial port class in .NET 2.0. It was suggested that upgrading to .NET 4 would fix the problem... and it did in almost all cases. If I am using the serial port class built-in to .NET to communicate with a USB-to-serial adapter, and the adapter is unexpectedly unplugged while the po...

What's wrong with my try: except: syntax?

Choking code: while port < 0 or port > 65535: try: port = int(raw_input("Enter port: ") except ValueError: print "Invalid port number." Result: File "/Users/.../Documents/.../CS 176A/TCPServer.py", line 10 except ValueError: ^ SyntaxError: invalid syntax ...

Checking exceptions in .NET solution (sources or binaries)

Hi, I am search a way to disable usage (**throw new exception **) of specific exception in our c# solution. If can I configure c# compiler and show compiled error if somebody try to throw a specific exception or, maybe, can I call a utility and analyze compiled binaries and show message if the specific exception was raises in our soluti...

What’s the rationale behind the Cocoa exception policy - or why use exceptions only for programmer errors?

What’s the rationale behind the Cocoa exception policy - or why use exceptions only for programmer errors? I understand that exception used to be rather expensive so one would not want to overuse them. But that changed with the modern runtime and it’s zero-cost exceptions. I also understand that the use of exceptions to do general contr...

Handling exceptions in exception block

Could someone please provide some good practice to handle exceptions in exception for example I have try { ... DeserializationResult deserialization = xmlSerializationService.deserializeFromXml(node); some code here } catch (Exception e) { try { //I need to create process result xml with error code and some details // creat...

How to handle Object Data Source Exception handling in DotNetNuke

I've created several DNN (5.2.3) modules and I'm finding that if an error happens on the object data source (ODS) DNN will then show that error to everyone. A sample (though not a ODS specific error in this case) is shown below. This has no meaning to user. The exception should really be "Thing not found" or something like that to the us...

Python Ignore Exception and Go Back to Where I Was

I know using below code to ignore a certain exception, but how to let the code go back to where it got exception and keep executing? Say if the exception 'Exception' raises in do_something1, how to make the code ignore it and keep finishing do_something1 and process do_something2? My code just go to finally block after process pass in ex...

How can exception break through try\catch block?

A citation from "The art of unit testing" book: In Rhino Mocks, strict mocks are created by calling the StrictMock method. Unexpected method call exceptions will always be thrown, even if your test contains a global try-catch clause, which you’d think would catch such an exception thrown from the isolation framework. So how e...

How to catch exceptions caused by a malformed layout-xml file?

public class MyActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //R.layout.main has an illegal element (e.g. no layout_height attribute) //But no e...

throw-catch logic

try { try { throw new Exception("From Try"); } catch { throw new Exception("From Catch"); } finally { throw new Exception("From Finally"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } The above code's output is: From Finally. Why it's not From Catch? -or- ...

A doubt about Exceptions

I was just playing around with exceptions in the visual studio and with the above code I was expecting that since my exception specification doesnt mention anything the bad_exception should have been thrown. But what actually happens is the exception gets caught by the apprpriate handler. Why so? Am i missing some setting or something in...

exception: Connection refused: connect.

Hi all, I am trying to connect a client (which is behind the company's proxy) to a server (JBoss AS 5.0) which is hosting an application (JavaFX). And I am facing the following error. exception: Connection refused: connect. java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Metho...