exception-handling

return statement and exception in try block in java

public class Test2 { public static void main(String args[]) { System.out.println(method()); } public static int method() { try { throw new Exception(); return 1; } catch (Exception e) { return 2; } finally { return 3; } } } in this...

Is this an Exception Handling abuse?

I have this method, that can return three different response. At first, it was supposed just only return two, so I make its return type to Boolean like: public static boolean isLoteWaitingForImage() And some business logic came out with that it can has another result, so the method was modified to public static boolean isLoteWaitin...

What's the alternative to exceptions in a deep Haskell recursion?

I'm trying to learn Haskell by writing little programs... so I'm currently writing a lexer/parser for simple expressions. (Yes I could use Alex/Happy... but I want to learn the core language first). My parser is essentially a set of recursive functions that build a Tree. In the case of syntax errors, I'd normally throw an exception (i.e...

ANSI C equivalent of try/catch?

I have some C code I'm working with, and I'm finding errors when the code is running but have little info about how to do a proper try/catch (as in C# or C++). For instance in C++ I'd just do: try{ //some stuff } catch(...) { //handle error } but in ANSI C I'm a bit lost. I tried some online searches but I don't see enough info abou...

Is having a property of type System.Exception in my custom class good in terms of memory usage/performance?

in my ASP.NET application, I am creating a new class to handle errors in my application and send them to a webservice which will save it in a table.Is there anything wrong in having a Property of type System.Exception class, in my new class ? Currently i have properties like "MethodName","ClassName","InnerException","StackTrace".When an ...

Exception handling in a three-tier Asp.Net application

1) To my understanding, in a three-tier Asp.Net application we should implement exception handling in the following way: a - we should put try-catch block around block of code ( located in any of the three layers ) from which we expect the page to gracefully recover from ( when this code generates an exception )? b - we shouldn’t put t...

What to include in the catch clause of Exception

I have a code that throws a bunch of Exceptions but each of them only contains a printStackTrace() method as shown below } catch (SecurityException e) { // TODO Auto-generated catch block System.err.println(e); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ...

Why do exceptions/errors evaluate to True in python?

In several places I have to retrieve some value from a dict, but need to check if the key for that value exists, and if it doesn't I use some default value : if self.data and self.data.has_key('key'): value = self.data['key'] else: value = self.default .... One thing I like about python, is that and/or bool...

trapping unhandled exceptions in .NET excel addins (XLL)?

I am trying to attach a unhandled exception handler for .NET excel addin. The problem is the exception handler is never called. AppDomain.CurrentDomain.UnhandledException doesn't work - never fires the event. Application.Current.DispatcherUnhandledException can't be used as Application is null in the excel addin code. how do you wire...

.NET WebServices Connectivity issue

I'm currently working on a piece of software designed in WPF that connects to a set of WebServices. The WebServices are defined in the app.config:endpoint of my application: <endpoint address="http://localhost:52870/WebServices/Service.svc" behaviorConfiguration="VanguardWebServiceBehavior" binding="wsHttpBinding" bindingConfigurat...

How to handle Zend_Exception's in preDispatch or init of an action when using a base controller?

As mentioned in the Zend Framework manual, I created a base controller. Subclassing the Action Controller By design, Zend_Controller_Action must be subclassed in order to create an action controller. At the minimum, you will need to define action methods that the controller may call. Besides creating useful function...

Three exception-handling Versions, which one is preferable?

I'm implementing a Zip-Wrapper (zlib minizip) and asking myself how i should handle exceptions properly. I'm thinking of three versions. Which one would you prefer, or is there a version i didn't thought about? The task of the function Install is to get a Zip-File from a Web-Server, unpack its content and delete the downloaded Zip-File....

COM+: ApplicationException instead of thrown exception

I got a ASP.net webservice which calls a COM+ component. A class in the COM+ component throws an exception which I want to handle. But ApplicationException is caught by the webbservice instead of the real exception. Why is that? Edit: Exception details System.ApplicationException: Error in the application. at System.Runtime.Intero...

Exception thrown in catch and finally clause

Hello everybody. On Tuesday I had my exam on Java at the University. While I passed the exam (:D) there is one question to which I didn't answer correctly. There was this snippet of code: class MyExc1 extends Exception {} class MyExc2 extends Exception {} class MyExc3 extends MyExc2 {} public class C1 { public static void main(Stri...

Handling Exception in MFC

I got this exception in my program: Unhandled exception at 0x0051cce0 in JSONDataParsing.exe: 0xC0000005: Access violation reading location 0x00000004 . I tried catching the Exception, but of no use. I know where the problem occurs. But wanted to know how I can trap the exception. I used try, catch block around the code wher...

Trace all handled exception

I am trying to understand why a deployed application is not working properly. I have pinned down the problem to a particular update routine. Sadly, the routine is embedded into a do nothing try-catch. bool requireUpdate = false; try { requireUpdate = !client.IsUpToDate(); } catch{ } I need a way to get the exception without having...

How to use boost::error_info correctly?

I'm trying to following the examples on this page: http://www.boost.org/doc/libs/1_40_0/libs/exception/doc/motivation.html The minute I try the following line: throw file_read_error() << errno_code(errno); I get an error: error C2440: '<function-style-cast>' : cannot convert from 'int' to 'errno_code' How do I get this to work?? ...

Techniques for XSLT exception handling

As of XSLT 2.0, as far as I know (correct me if I’m wrong), there’s no native mechanism in the language for exception handling. I have some stylesheets that attempt to do some processing on specified chunks of an input document, copying everything else unaltered. There are rare exceptional conditions that I can’t easily detect before I ...

C++ exception handling and error reporting idioms

In C++, RAII is often advocated as a superior approach to exception handling: if an exception is thrown, the stack is unwound, all the destructors are called and resources are cleaned up. However, this presents a problem with error reporting. Say a very generic function fails, the stack is unwound to the top level and all I see in the l...

How to stop execution of a Request in Kohana?

Let's say I have a controller template with a before function like so... public function before() { parent::before(); if ($this->request === Request::instance()) { // its a main request, throw an exception or redirect Request::instance()->redirect('/'); } else { // ok } }...