try-catch

Using bool (return Type) to handle exceptions or pass exception to client?

I am trying to find out the best way of handling exceptions, I have a number of layers to my application and started to use a return type of BOOL i.e. if it fails then return False and if it succeeds return True.. This works great in methods like SaveMyRecord(somerecord); as i am passing in values and don't require anything returned so...

Difference between while (x = false) and while (!x) in Java?

Sorry, I'm new to Java, so this question might be unclear. I have been recently dealing with enclosing a try and catch statement in a while loop, because I wanted to make sure that getting input was enclosed from the rest of the program. I have come across a problem where using an exclamation mark in front of a variable in the while con...

C# Catch bool exception when using return

I'm using the code below and occasionally boolUpdate is not TRUE or FALSE and I get an exception, I can't surround this with a TRY CATCH block as it is using 'return', how can I catch this correctly? if (!Boolean.Parse(boolUpdate)) return true; ...

Is there any performance advantage over running code outside try,catch blocks?

I am curious to know if I should minimize the code that goes inside a try/catch block or it really does not matters. public bool ObjectExists(string stringTest, string againSomethingElse) { if(true) {} else {} //Code here is better/worst/same try { //Versus code inside try/catch block...

catch exceptions in Codegear CBuilder 2007 Forms

Hi, I have the problem to catch an EInOutError exception in CBuilder 2007 that is thrown inside an AsyncPro component. I have put a "try" statement around the Application->CreateForm() calls, but this covers only up to the constructor of the classes. From there the Forms run in their own thread and exceptions are not catched. Does anybo...

How to add a Try/Catch to SQL Stored Procedure

CREATE PROCEDURE [dbo].[PL_GEN_PROVN_NO1] @GAD_COMP_CODE VARCHAR(2) =NULL, @@voucher_no numeric =null output AS BEGIN DECLARE @NUM NUMERIC DECLARE @PNO NUMERIC SET @PNO = 0 DECLARE @PNO1 NUMERIC SET @PNO1=0 -- begin transaction IF NOT EXISTS (select GLDC_...

What is the difference between throw and throw with arg of caught exception?

Imagine two similar pieces of code: try { [...] } catch (myErr &err) { err.append("More info added to error..."); throw err; } and try { [...] } catch (myErr &err) { err.append("More info added to error..."); throw; } Are these effectively the same or do they differ in some subtle way? For example, does the first one c...

How should I refactor a long chain of try-and-catch-wrapped speculative casting operations

I have some C# code that walks XML schemata using the Xml.Schema classes from the .NET framework. The various simple type restrictions are abstracted in the framework as a whole bunch of classes derived from Xml.Schema.XmlSchemaFacet. Unless there is something I've missed, the only way to know which of the derived facet types a given fac...

When is it good to use Exceptions on PHP?

I've been developing big applications using try/catch to handle all the exceptions and errors; however, I've been trying to figure out: When is it correct to use a try/catch statement? Is there a good practice/rule for try/catchs? Currently I'm building a SEO library for my PHP Framework and I have a "small" function, and I asked mysel...

Closing sockets in python

I'm modifying Python code that have this form: def foo(self): try: connect socket except Exception, e: some error reporting stuff return an error use the socket do some other stuff if some condition: return do some more stuff socket.close() return normally Coming from ...

How to write an empty indentation block in Python?

The runtime keeps telling me: expected an indented block But I don't want write nothing inside my except block, I just want it to catch and swallow the exception. ...

Raise an error manually in T-SQL to jump to BEGIN CATCH block

Is it possible to raise an error in a stored procedure manually to stop execution and jump to BEGIN CATCH block? Some analog of throw new Exception() in C#. Here is my stored procedure's body: BEGIN TRY BEGIN TRAN -- do something IF @foobar IS NULL -- here i want to raise an error to rollback transaction -- do something next C...

How to catch a java unchecked/runtime exception (specifically SecurityException)

Hi all, I have java class with a method which gets an image from a website: private Image image; private int height; private int width; private String imageUri; public Image getImage() { if (image == null) { log.info("Fetching image: " + imageUri); try { URL iURL = new URL(imageUri); ImageIcon ii = new ImageIcon(iURL); i...

Try-Catch and how throw work in catch block

I have question about throw. How will the throw work in the following code? Does the catch block return false? try { //code } catch(Exception ex) { throw; return false; } ...

response.redirect and throw in catch block

What will happen in the following scenario? Will it throw work after response.redirect? Or do I need to use Response.Redirect in catch block of main method where it throws exception call stack.... try { //code } catch(Exception ex) { Response.Redirect("Error.aspx"); throw; } ...

C# catch a stack overflow exception

Hello, I got a recursive call to a methode that throw a stack overflow exception. The first call is surrounded by a try catch block but the exception is not caught. Do the stack overflow exception behave in a special way ? Can I catch/handle properly the exception ? NB : if relevant : the exception is not thrown in the main thread...

Is try/catch around whole C# program possible?

A C# program is invoked by: Application.Run (new formClass ()); I'd like to put a try/catch around the whole thing to trap any uncaught exceptions. When I put it around this Run method, exceptions are not caught; control only returns here when the program terminates after an uncaught exception. Where can I put try/catch to cover the...

Is it bad to use nested Try..Catch blocks like this?

Is this a bad idea? Is there a better way to achieve the same effect? // assume that "name" is a string passed as a parameter to this code block try { MainsDataContext dx = new MainsDataContext(); try { Main m = dx.Main.Single(s => s.Name == name); return m.ID; } catch (InvalidOperationException) ...

try finally mystery

Consider, static void Main(string[] args) { Console.WriteLine(fun()); } static int fun() { int i = 0; try { i = 1; return i; } catch (Exception ex) { i = 2; ...

image src doesnt change after upload

Hi all i am making an upload with Ajaxupload plugin and i am using this function in OnComplete event of ajaxupload; function degis(){ var a = "<?php echo $id; ?>"; document.getElementById("imga").src = "../artwork/"+a+"/logo.jpg?dummy=371662"; document.getElementById("imga").style.width = "500px"; document.getElementById("imga").style....