exception-handling

How to get the current exception without having passing the variable?

I am looking for a way to retrieve the current exception without having to pass it as a variable. Suppose the following code public void MakeItFail() { try { throw new FailException(); } catch // Yes I'm aware that this shouldn't be done, but I don't want to go through all the code base and change it { ...

Question about multiple 'catch'

Can anyone tell me why the output of this class is 'xa'? why the other exception(RuntimeException and Exception ) won't be caught? public class Tree { public static void main(String... args) { try { throw new NullPointerException(new Exception().toString()); } catch (NullPointerException...

How do I implement a fibonacci sequence in java using try/catch logic?

I know how to do it using simple recursion, but in order to complete this particular assignment I need to be able to accumulate on the stack and throw an exception that holds the answer in it. So far I have: public static int fibo(int index) { int sum = 0; try { fibo_aux(index, 1, 1); } catch (IntegerExcepti...

Web Service Exception Handling

I have a Winforms app that consumes a C# Webservice. If the WebService throws an Exception my Client app always get's a SoapException instead of the "real" Exception. Here's a demo: [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] pu...

How to use SQLErrorCodeSQLExceptionTranslator and DAO class with @Repository in Spring?

I'm using Spring 3.0.2 and I have a class called MovieDAO that uses JDBC to handle the db. I have set the @Repository annotations and I want to convert the SQLException to the Spring's DataAccessException I have the following example: @Repository public class JDBCCommentDAO implements CommentDAO { static JDBCCommentDAO i...

Writing catch block with cleanup operations in Java ...

I was not able to find any advice on catch blocks in Java that involve some cleanup operations which themselves could throw exceptions. The classic example is that of stream.close() which we usually call in the finally clause and if that throws an exception, we either ignore it by calling it in a try-catch block or declare it to be reth...

When is it appropriate to use error codes?

In languages that support exception objects (Java, C#), when is it appropriate to use error codes? Is the use of error codes ever appropriate in typical enterprise applications? Many well-known software systems employ error codes (and a corresponding error code reference). Some examples include operating systems (Windows), databases (Or...

After calling a COM-dll component, C# exceptions are not caught by the debugger

I'm using a COM dll provided to me by 3rd-party software company (I don't have the source code). I do know for sure they used Java to implement it because their objects contain property names like 'JvmVersion'. After I instantiated an object introduced by the provided COM dll, all exceptions in my C# program cannot be caught by the VS ...

Implement Exception Handling in ASP.NET C# Project

hi, I have an application that has many tiers. as in, i have... Presentation Layer (PL) - > contains all the html My Codes Layer (CL) -> has all my code Entity Layer (EL) -> has all the container entities Business Logic Layer (BLL) -> has the necessary business logic Data Logic Layer (DLL) -> any logic against data Data Access Layer (DA...

Unable to catch exception from Activator.CreateInstance.

OK, I admit it this code will just look weird to you, and that's because it is weird. This is just code to reproduce the behavior, not code I want to use. class Program { static void Main(string[] args) { try { Activator.CreateInstance(typeof(Func<int>), new object[] { new object(), IntPtr.Zero }); ...

Help with Exception Handling in ASP.NET C# Application

hi, yesterday i posted a question regarding the Exception Handling technique, but i did'nt quite get a precise answer, partly because my question must not have been precise. So i will ask it more precisely. There is a method in my BLL for authenticating user. If a user is authenticated it returns me the instance of the User class which...

Handling PHP exceptions with JQuery

Hello, I'm using JQuery to call a PHP function that returns a JSON string upon success or throws some exceptions. Currently I'm calling jQuery.parseJSON() on the response and if it fails I assume the response contains an exception string. $.ajax({ type: "POST", url: "something.php", success: functio...

Try/Catch with jquery ajax request

I am trying to build a Google Chrome extension that makes an ajax request. Something similar to the GMail Checker extension. The problem is that when I do the request using jquery, and I put in the wrong username/password, it fails silently, with the error callback function ignored. If I move the ajax call out of the background.html scr...

Is there a global error handling location in WCF comparable to Global.asax's Application_Error in ASP.Net?

I'm creating an WCF service and I need to implement error handling. In ASP.Net it was possible to centralize error handling in the Application_Error event handler in the global.asax file. Is there a comparable solution for WCF other than aspnet compatibility mode? I cannot use aspNetCompatibilityEnabled because the transport is not ...

Keep Hibernate Initializer from Crashing Program

I have a Java program using a basic Hibernate session factory. I had an issue with a hibernate hbm.xml mapping file and it crashed my program even though I had the getSessionFactory() call in a try catch try { session = SessionFactoryUtil.getSessionFactory().openStatelessSession(); ...

How to break on unhandled exceptions in Silverlight

In console .Net applications, the debugger breaks at the point of the throw (before stack unwinding) for exceptions with no matching catch block. It seems that Silverlight runs all user code inside a try catch, so the debugger never breaks. Instead, Application.UnhandledException is raised, but after catching the exception and unwindin...

Global Exception Handlers in Java

I am thinking of setting up a global, default Exception handler for my (Android) Mobile application(which uses Java syntax) using Thread.setDefaultUncaughtExceptionHandler(...) call. I am thinking of just displaying an Alert Dialog with appropriate message to the user. Are there any gotchas, caveats and rules that one needs to follow wh...

Handling service unavailable errors in asp.net

Hi, I have an asp.net application which will always interact with wcf service to transact with the data. My question here is if the serivce is not running or some reasons got timed out. How do i need to handle the serivce exception from my consuming application. We are using faultcontract exceptions for handling any runtime exception...

Globally Log Catch Exception e

Suppose that I have a legacy java application with thousands of lines of code which do: try { // stuff } catch (Exception e) { // eat the exception } Is there any global option that I could flip or 3rd party JAR which would log all "eaten" exceptions? I know that I could do a massive find replace (search for catch (Exception e)...

How do I add information to an exception message without changing its class in ruby?

How do I add information to an exception message without changing its class in ruby? The approach I'm currently using is strings.each_with_index do |string, i| begin do_risky_operation(string) rescue raise $!.class, "Problem with string number #{i}: #{$!}" end end Is there a better way? ...