Try Catch Question about Finally

Hi folks,

Inside of a function that returns an integer I do a databse call. Se code below.

  1. If I do the following and there is an exception does the finally get performed?
  2. If there is an exception and the "ParamReturn.Value" is 1 what gets returned.

I'm just a little confused on the sequence of events.

Catch ex As Exception
   Return 2
End Try
Return ParamReturn.Value

John Belthoff
Dodge, Duck, Dip, Dive & Dodge
If a man can dodge a wrench, he can dodge a ball!
12/12/2005 1:40:02 PM 91979 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 42

The finally block always gets executed, whether there is an exception or not. You are telling the method to return a 2 on an exception, so it always will return that when an exception occurs.



12/12/2005 2:18:40 PM
Thank you. That is what I was hoping for.
John Belthoff
Dodge, Duck, Dip, Dive & Dodge
If a man can dodge a wrench, he can dodge a ball!
12/12/2005 3:55:29 PM
if i use "exit sub" in the catch  statement, will the "finally" run the code? 
12/12/2005 9:39:23 PM

Similar Artilces:

Getting Started with .net and a few questions
Hello I've done some asp and php programming along with various other languages in the past and slowing getting my head around .net.I have a small project of creating a Holiday Booking system on our Intranet and just trying to get the first part to work properly will hopefully get me sorted for the whole project. The Intranet is running on .net 2 and I prefer to use the VB code rather than C#. This is connecting to an SQL server.My initial page that I am trying to create is just for an admin user to view which dates in a table have been specified as Bank Holidays and be able to add ...

Try/Catch/Finally Question
I am trying the Try/Catch/Finally and I am getting the "myconn" is not declared. I didn't get this error until I put in the Try/Catch/Finally, any reason why? Try Dim webnew As Boolean = TrueDim WebID As IntegerDim contactID As IntegerDim reportID As IntegerDim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _"c:\accmon\database\accmon.mdb" & ";" '********************************************'Load Website tableDim MySQL As String = "Insert into websites (agencyID, url, service, addressIP, webnew)" & _  "Values (@DOTAgency, @URL, @ServiceType, @IPAddre...

Newbie Question
I have a new project which has just started. One of the requirements is to generate XML files. Do I have to create schema files? Does anyone have a tutorial or sample code to help me get started. I have some background using XML, but not in .NET. Thx Mark How to create a new xml file with XmlDocument? More examples hereSonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Controls Forum Thanks, this is very helpful. What do I need to do extra to setup the schema for this xml file? Is the schema really necessary as well? Thx Mark You dont need to define any sc...

using try-catch-finally to get DB errors
Lets say I'm using the following code to do something with database, how do I get any database error and display it as my own error message?1 // Declare objects 2 SqlConnection conn; 3 SqlCommand categoryComm; 4 SqlCommand subjectComm; 5 SqlDataReader reader; 6 7 // Read connection string from web.Config 8 string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString; 9 10 // Initialise the connection 11 con...

Try Catch Finally (Finally omit)
Hi, I am using VS.NET 2005. In previous version of VS.NET, we have Try, Catch & Finally, but why in VS.NET 2005 the Finally omit in VB.NET and it is still using in C#. I am asking in VB.NET as if we type Try and enter then only Try & Catch came but bydefault Finally not came and we required to manually enter it but but in C# when we type Try, the Catch & Finally byself come. Thanks in Advance. Einstein_Lover: Hi, I am using VS.NET 2005. In previous version of VS.NET, we have Try, Catch & Finally, but why in VS.NET 2005 the Finally omit in VB.NET and it is still using...

When Error accured. Process will run to the CATCH clause then run Finally Clause. But When Error not accured, Process will run to Finally Clause. So, Error accured or not, Finally Clause certain will to be run it. I don't know, if this, script in Finally Clause or after Finally's script, what's different? Thanks Leo I don't understand the question... but Finally is executed if the exception is thrown or not. "LEO" <> wrote in message > When Error accured. Process will ru...

Debug.Assert, try/catch/finally block strategy question
I'm sick of putting break points in try catch blocks and finding errors that way when I'm debugging I love Debug.Assert - Instead of putting break points in every catch block, I wish there was a way to do something like assert...Get ready to blast your energy levels into high gear with Sedgewick Energy Drink. High powered adaptogenic herbs mixed with potent levels of B-vitamins and...Please disregard the contents of this post. what in the world are you doing debugging like that? Use the command window, and other tools also. There is no better means of doing anything than to ste...

trying to get started and i am getting this error
when i go to, i get: DotNetNuke Upgrade Error The Assembly Version ( [ASSEMBLYVERSION] ) does not match the Database Version ( [DATABASEVERSION] ) ERROR: Could not connect to database. Could not find file 'd:\hosting\nmoran26\Providers\DataProviders\AccessDataProvider\DotNetNuke.mdb'. Any suggestions will be appreciated. Thanks, Nicole Do you have a username and password set on your database? Make sure you follow the steps mentionned in the Readme.txt located in the documentation folder. In any case make sure your credentials for yo...

try catch finally / response.redirect / response.end flow control question
Hi Guys, Can any one tell me if the finally block would be executed in the following example (assuming that returned false because no records were found).   Many Thanks! DanielTry dbCon = New SqlConnection(myconnectionstring) dbCon.Open() dbCom = dbCon.CreateCommand() strSQL + "SELECT * FROM bookings WHERE ID &gt; 9000" dbCom.CommandText = strSQL dbReader = dbCom.ExecuteReader() If dbReader.Read() Then 'init fields Else Response.Redirect("main.aspx") End if Finally dbReader.clo...

I am getting serious issues with the PB Statement TRY...CATCH...FINALLY...END TRY I am using: TRY ds_buffers[1].settransobject(SQLCA) Rows_Page=ds_buffers[1].retrieve(mdl_sk_itemref) ValColPage=ds_buffers[1].Object.sk_page[1,Rows_Page] CATCH (type of erro) messagebox("","") {FINALLY } END TRY I am getting Sintax Error. Anybody could help me out? this is my use of Try-catch TRY [...] CATCH (ctscomponents_createexception e) [...] FINALLY [...] END TRY It's your CATCH clause. Here's an excerpt from the help file...

What if Finally throws an error in try-catch-finally?
can anyone tell me What if Finally throws an error in try-catch-finally? Mark as Answer if you find the post useful. It'll throw an exception - being in the finally block doesn't exclude your code from throwing exceptions.You can put another try/catch block inside the finally block if you want to trap exceptions there.  Then the exception that is generated in the Finally block will propagate up the call stack until a Catch block is found For example Sub Main()  Try    Foo()  Catch    Console.Wri...

Catch, Try Question and Stored Procedure Question
 Hi, i know that catch ex as SQLexception is for catching SQL error right? Then what is "catch ex as exception" for?  and also what is "Finally" used for? Another thing about stored procedure, what is the range of values that i can use for setting my own return values? like if exist (select * from table) return -101 <--- what is the range of numbers i can use these?and what are the other numbers like the positive numbers for? thanks To Under Stand the Try Catch and FInally you must read the following articles

.NET 2005 TRY..CATCH with SQL RAISERROR Not Catching
Is there a reason why the following code does not raise an error in my .NET 2005 application? Basically I have a try..catch in my stored procedure. Then I have a try...catch in my .NET application that I want to display the error message. But, when the stored proc raisses the error, the .net code doesn't raise it's error. The .NET code DOES raise an error if I remove the try..catch from the SQL proc and let it error (no error handling), but not if I catch the error and then use RAISERROR to bubble-up the error to .NET app. (I really need to catch the error in my SQL proc and rollbac...

Getting "Problem in Mapping Fragment starting at line ..." error when trying to create table mappings for table associations in ADO.NET Entity Framework

Web resources about - Try Catch Question about Finally -

West Lothian question - Wikipedia, the free encyclopedia
He illustrated his point by pointing out the absurdity of a Member of Parliament for West Lothian being able to vote on matters affecting the ...

Australia vs New Zealand Cricket Third Test: Mitchell Starc batting with foot injury raises questions ...
Steve Smith has defended the strange decision to send Mitchell Starc out to bat with a broken foot when only two runs were required for victory ...

Police question owner of dumped vehicle in Andrew Carville murder investigation
Police attempt to piece together the last movements of Evatt man Andrew Carville whose body was found on November 19.

Australia vs New Zealand third cricket Test: Michael Hussey questions Grant Baldwin call
Former Test star Michael Hussey has accused the Australian cricket team of being &quot;unprofessional&quot; for allowing their massage therapist ...

Question Of The Day: First-ever car ride?
Filed under: Automotive History The first time you were ever in a motor vehicle, what was it? Continue reading Question Of The Day: First-ever ...

Dwight Howard on If He Learned Anything from Kobe Bryant: 'Next Question' - Bleacher Report
The basketball world had itself a love-fest for Kobe Bryant on Sunday night. Everyone except Dwight Howard took part in it...

Race is a "broad and protean" matter, presenting "rich, difficult questions," and "Any insistence otherwise ...
John McWhorter writes, in a WSJ piece, "Closed Minds on Campus" : The idea that only the naive or the immoral would question issues connected ...

Pope Francis dodges question of condoms in AIDS fight
Pontiff says there's more important issues to discuss than whether the Church's position on contraception has made AIDS crisis in Africa worse ...

Four new Laquan McDonald shooting videos raise more questions
Newly released videos from four additional police vehicles at the scene of the 2014 shooting of Laquan McDonald raise questions about how the ...

Ask Me Anything: Questions 1 & 2
I recently started a new feature where you can ask me anything by recording a video. Turns out that I got two closely related questions about ...

Resources last updated: 12/1/2015 7:07:15 AM