23
голосов
2ответов
7120 просмотров

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 exceptio...

117
голосов
9ответов
102482 просмотров

C# catch a stack overflow exception

I have a recursive call to a method that throws a stack overflow exception. The first call is surrounded by a try catch block but the exception is not caught. Does the stack overflow exception behave in a special way? Can I catch/handle the exception properly? Not sure if relevant, but additio...

3
голосов
2ответов
3550 просмотров

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; }

4
голосов
3ответов
2216 просмотров

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; }

1
голосов
5ответов
5716 просмотров

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

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 U...

1
голосов
7ответов
6202 просмотров

Unreachable return statement in Java

I was recently quickly writing this little function 5 minutes ago when i got the compiler error unreachable statement private static boolean isTransientField(String name, Class beanClass) { try { Field field = beanClass.getDeclaredField(name); return (field.getMod...

38
голосов
5ответов
107350 просмотров

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 roll...

39
голосов
2ответов
25027 просмотров

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.

4
голосов
3ответов
7542 просмотров

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....

1
голосов
3ответов
175 просмотров

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 ...

3
голосов
6ответов
573 просмотров

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 wh...

21
голосов
2ответов
6317 просмотров

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 s...

43
голосов
5ответов
141276 просмотров

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 tr...

1
голосов
1ответов
254 просмотров

catch exceptions in Codegear CBuilder 2007 Forms

I have the problem to catch an EInOutError exception in C++ Builder 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 a...

1
голосов
4ответов
351 просмотров

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 { ...

2
голосов
5ответов
5235 просмотров

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;

3
голосов
8ответов
16517 просмотров

What is the 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 m...

5
голосов
6ответов
3260 просмотров

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 val...

2
голосов
3ответов
1894 просмотров

MVC Catch All route not working

My first route: // Should work for /Admin, /Admin/Index, /Admin/listArticles routes.MapRoute( "Admin", // Route name "Admin/{action}", // URL with parameters new { controller = "Admin", action = "Index"...

4
голосов
2ответов
1179 просмотров

Is it a bad idea to put frequent file I/O operations within a SyncLock block?

Say I have some code that does this: Public Function AppendToLogFile(ByVal s As String) As Boolean Dim success As Boolean = True Dim fs As IO.FileStream = Nothing Dim sw As IO.StreamWriter = Nothing Static LogFileLock As New Object() SyncLock LogFileLock Try ...

3
голосов
3ответов
3126 просмотров

Stop Inserting in Table if record already exists

I have sql server procedure, please see below. ALTER PROCEDURE [dbo].[uspInsertDelegate] ( @CourseID int, @CPUserID int, @StatusID int, @CreateUser varchar(25) ) AS SET NOCOUNT OFF; INSERT INTO tblDelegate ( CourseID, CPUserID, StatusID, ...

3
голосов
2ответов
882 просмотров

Logging SQL Errors

SQL Server 2008 has a new try/catch structure. If I encounter an error in a sequence of nested stored procedures, I like to log the call stack in an error table. The problem is that if I have started a transaction (which will be true for operations that update the db), an records written to the...

47
голосов
7ответов
41117 просмотров

Java exception not caught

Why are some exceptions in Java not caught by catch (Exception ex)? This is code is completely failing out with an unhandled exception. (Java Version 1.4). public static void main(String[] args) { try { //Code ... } catch (Exception ex) { System.err.println("Caught Exce...

0
голосов
1ответов
659 просмотров

TeamCity 4.5 not recognizing trycatch element in nant script

Our team recently upgraded to TeamCity 4.5.4 but we're having trouble with TeamCity running our nant build scripts. We now get an error message saying: Invalid element <trycatch>. Unknown task or datatype. We haven't changed our build script during or after the upgrade so I'm wondering wh...

20
голосов
4ответов
38147 просмотров

Handle error when getimagesize can't find a file

when I'm trying to getimagesize($img) and the image doesn't exist, I get an error. I don't want to first check whether the file exists, just handle the error. I'm not sure how try catch works, but I want to do something like: try: getimagesize($img) $works = true catch: $works = flase

7
голосов
2ответов
2048 просмотров

C# Real Time Try Catch

I'd like a response from someone who actually does real-time programming in C# or who really understands the language internals. I know that exceptions should not be used to handle normal processing, but only to detect error conditions. There is plenty of discussion on that topic. I'd like to ...

3
голосов
3ответов
735 просмотров

Catch a type error in C++

How do i check if a result is of the right type(int, float, double, etc.) and then throw and catch an exception in case it's not? Thanks all, Vlad.

6
голосов
9ответов
4618 просмотров

Is it "bad" to use try-catch for flow control in .NET?

I just found in a project: try { myLabel.Text = school.SchoolName; } catch { myPanel.Visible = false; } I want to talk to the developer than wrote this, saying that incurring the null exception (because school might theoretically be null, not myLabel) would virtually make the computer ...

42
голосов
6ответов
12153 просмотров

How does C++ exception handling translate to machine code

Mentally, I've always wondered how try/throw/catch looks behind the scenes, when the C++ compiles translates it to assembler. But since I never use it, I never got around to checking it out (some people would say lazy). Is the normal stack used for keeping track of trys, or is a separate per-thr...

278
голосов
11ответов
76146 просмотров

Do try/catch blocks hurt performance when exceptions are not thrown?

During a code review with a Microsoft employee we came across a large section of code inside a try{} block. She and an IT representative suggested this can have effects on performance of the code. In fact, they suggested most of the code should be outside of try/catch blocks, and that only import...