exception-handling

What circumstances should someone "try...catch"? Does this apply to libraries?

Suppose you're designing an application (WebApp, Desktop, anything) and you need to define exception handling for the code. Since you want to make things reusable, what logic should you follow when handling exceptions? Are there any patterns to follow? For example, if some DLL is going to use the network and the network is unreliable, ...

Exception Error when I try to initialize hudson.war

Hi there, I have installed hudson on Ubuntu server and then run java -jar hudson.war, giving me this exception error message: Status Code: 500 Exception: The error below occurred during context initialisation, so no further requests can be processed: java.lang.ExceptionInInitializerError at java.lang.Class.initiali...

Exception propagation through nested loops/calls

I'm having trouble understanding how exceptions should propagate. My code (quite similar to the generic code below) executes otherCode() and fails to continue outer when doSomething() throws the exception. I need to loop over parsing a bunch of files, some of which may be formated incorrectly (causing an exception), and then loop over ...

Using Spring 3 @ExceptionHandler with commons FileUpload and SizeLimitExceededException/MaxUploadSizeExceededException

Hi All, I am having trouble with catching and gracefully handling commons fileupload's FileUploadBase.SizeLimitExceededException or spring's MaxUploadSizeExceededException when uploading large files. From what I can tell these exceptions are thrown during data binding, before the controller is actually reached, therefore resulting in ...

Exception Handling in java error in the following code

import java.io.*; public class Mainclassexec { public static void main(String[] args) { String input = null; try { String capitalized = capitalize(input); System.out.println(capitalized); } catch (NullPointerException e) { System.out.printl...

executing multiple catch blocks

This is a bit abstract, but is there any possible way to throw an exception and have it enter multiple catch blocks. IE if it matches a specific exception followed by a non specific. catch(Arithmetic exception) { //do stuff } catch(Exception exception) { //do stuff } I don't really NEED to do this I just need to this I just am wo...

OutOfBoundsException for TicTacToe Game; Issue: arrays?

I am the beginnings of writing a tic-tac-toe game. I just ran it and got the following stack trace: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:571) at java.util.ArrayList.get(ArrayList.java:349) at TicTacToe.isMarked(TicTacToe.java:23) at TicTac...

Detect 404 without catching exceptions

Simple function: Check if a webserver returns a non-200 HTTP status. Private Function RemoteFileOk(ByVal Url As String) As Boolean Dim req As HttpWebRequest = TryCast(WebRequest.Create(Url), HttpWebRequest) req.Method = "HEAD" Dim rsp As HttpWebResponse = TryCast(req.GetResponse(), HttpWebResponse) Return (rsp.StatusCode = Http...

I need a small change in the output help me pls

import java.util.regex.*; import java.io.*; class Patmatch{ static String str = ""; public static void main(String[] args){ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter name to see match"); try{ str = br.readLine(); }...

How to stop exception alerts from going bezerk

Let's say you have a .NET system that needs to send out email notifications to a system administrator when there's an error. Example: try { //do something mission critical } catch(Exception ex) { //send ex to the system administrator //give the customer a user-friendly explanation } This block of code gets called hundred...

.Net: Try...Catch paranoia - where does it end?

I think I have something like "programmer's OCD". I like my code to be esthetical and clean, and I want it to be "perfect" (as in handling all possible situations correctly and pretty). Often I find myself spending a lot of time just going over the same areas again and again to see where I can optimize and where I can fool-proof. So whe...

exception handling for databound dropdowns in listviews

One common scenario we run into is with a drop down being databound inside the edit template of a ListView. This usually works pretty well, but I cannot figure out a good way to handle exceptions, for example, look at this error from our website: Server Error in '/' Application. 'ddlLender' has a SelectedValue which is invalid because...

MVC2 Handling Exceptions from RenderAction

My controller is decorated with [HandleError] and [HandleError(ExceptionType=typeof(CustomException), View="CustomView")]. I have views that consist of multiple partial views from multiple controllers, so we're displaying our partial views using <% RenderAction(...) %> but now we have a case where our action being rendered is throwing a...

Asserting exceptions in Java, how?

This might be a conceptually stupid question, but it also might not and since I am still a student I think I should I have no problem asking. Imagine you have a method that if given certain conditions it will throw an NumberFormatException. I want to write a Unit Test to see if the exception is being correctly thorwn. How can I achieve ...

Which exception to raise if a given string does not match some format?

This is a follow up to an older question. Given a ISBN number, e.g. 3-528-03851-5 which exception type should I raise if the passed in string doesn't match the format X-XXX-XXXXX-X? ...

Spring 3.0 MVC ExceptionHandler

I'm writing my Exception Handler from Spring MVC controller and I have the following code: @ExceptionHandler(NullPointerException.class) public ModelAndView handleMyException(NullPointerException exception) { System.out.println(exception.getMessage()); ModelAndView modelAndView = new ModelAndView("/errors/404"); ...

Log messages lost in few specific situations

I am using java.util.logging to do all the logging of my application. Until recently, I was using the logging facility without any specific configuration. Everything worked as expected, all the logs were visible in the console (stderr) Now, I wanted to customize the configuration for my logs. I want the logs to be displayed on the cons...

ASP.NET Custom errors for developer machines

Does this ever happen to you? You are sitting at your development machine and you are made aware of an unhandled exception in a deployed asp.net application. You visit the deployed web app. You can't see the exception detail in your browser, because custom errors is set to remote only. So you have to login to the web server and instigat...

How do I catch a C++ exception?

In my C++ app, I'm making a call to System() that crashes the app sometimes (it's a service). I'd like to catch the exception that is thrown and log it. I don't know what exactly to catch, though, and I can't even do a blanket catch: try { system(myCommand); } catch (...) { Log("Error!"); // this is a custom log method } That do...

Common exceptions while executing sql queries

I have read that catching the particular exception separately enhanced the performance so I just wanted to know what are the most common exception that might generate while executing any sql query ...