.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Catch Block question

Posted By:      Posted Date: August 30, 2010    Points: 0   Category :Sql Server
What are the scenarios in which a t-sql catch block will not be called?   I have a SP which does partition management, sometimes i see that partitions have not been properly created... but still the catch block was never called. This is getting very hard to debug.   Can it be that in some timeout scenarios the catch block is not called?

View Complete Post

More Related Resource Links

try catch block

Hi Guys, I have a very simple question. whether to put the select stmt in try/catch or not? Its advantage,disadvantage if any will be of great help.~Technology Analyst~

Try-Catch block cannot handle exceptions when contacting a Silverlight Client using net.tcp Duplex W

I have created a simple duplex WCF for Silverlight 4 clients, using net.tcp binding (.NET Framework 4.0)  The client interface is declared as <ServiceContract()> _ Public Interface IServiceClient <OperationContract(IsOneWay:=True)> _ Sub SendUpdate(ByVal allRecords As List(Of String)) End Interface while the service interface is declared as <ServiceContract(Namespace:="SilverlightService", CallbackContract:=GetType(IServiceClient))> _ Public Interface IService <OperationContract(IsOneWay:=True)> _ Sub Connect() End Interface The service code is implemented like: <ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Multiple, InstanceContextMode:=InstanceContextMode.Single)> _ <Activation.AspNetCompatibilityRequirementsAttribute(RequirementsMode:=Activation.AspNetCompatibilityRequirementsMode.Allowed)> _ Public Class Service Implements IService 'Keep the list of all the active/connected clients: Public _clients As List(Of IServiceClient) = New List(Of ITrackServiceClient) Public Sub Connect() Implements IService.Connect Dim client = OperationContext.Current.GetCallbackChannel(Of IServiceClient)() Dim clientExist = From p In _clients _ Where p Is client _ Select p If clientExist.Count() = 0 Then Monitor.Enter(_clients) _clients.Add(client) Monitor.E

why doesn't this catch block get reached?

I have code for sending an email.  I set a value in my config file for that would throw an smtpfailedrecipient exception.  This exception is being thrown but it isn't reaching the catch block.I get an smtpfailedrecipientexception that is at the send method in the try block.  The error says that the "exception was unhandled by user code".  I don't understand why the catch block isn't being reached.  I thought this would be reached in this situation.  I thought this is what the catch block was for.Can someone please help me understand how to design this better or why this isn't working the way I thought it would? try { client.Send(message); <-- this throws the exception } catch (SmtpFailedRecipientsException ex) { #region Catch logic for (int i = 0; i < ex.InnerExceptions.Length; i++) { SmtpStatusCode status = ex.InnerExceptions[i].StatusCode; if (status == SmtpStatusCode.MailboxBusy || status == SmtpStatusCode.MailboxUnavailable) { lblMessage.Visible = true; lblMessage.Text = "Deli

Embedded code block question

Hello,i know it's a very basic problem but i can't use an asp.net code block the way i want.I have used those before but it seems i encountered a case i haven't seen before.<asp:SqlDataSource ID="SqlDataSourcetblCategoriesPourListe" runat="server" ConnectionString="<%$ ConnectionStrings:BottinConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT label from mytable WHERE (HOrder = @HOrder)))"> <SelectParameters> <asp:QueryStringParameter DefaultValue="<% (int)GetDefaultValue()%>" Name="HOrder" QueryStringField="HOrder" /> </SelectParameters> </asp:SqlDataSource>Whenever i run this, i get an exception:Syntax error converting the nvarchar value '<% (int)GetDefaultValue()%>' to a column of data type int.How can i avoid this ?I am not doing it in the code behind because i use nested gridviews and sqldatasources.  Can't access nested sqldatasources from code behind, as far as i know.

Try Catch block is not work that try block failed but catch block is not excuted


I am facing the problem: Try Catch block is not work that try block failed but catch block is not excuted.

In my case, I tried to excuted the sql like below:

begin try

update [table] set [column] = abc

end try

begin catch
 select 'catch error'
end catch


The [column] is numeric format, but data set to it is not valid number.

When excute this sql, the following error prompt out:

Invalid column name 'abc'.

And the catch block has not been excuted.


I want to know what happen in this case.

Moreover, I found an article talks about the similar case too:



Is there any solution so that I can catch the error without stopping the batch?

Thanks a lot.

dm_fts_parser inside try-catch block


Hi, I'm working on a project and have a code similar to the code posted below and I would like to understand why the CATCH block is never executed. If the try catch is removed the dm_fts_parser will send an error complaining search string syntax, however inside a try-catch block the code will silently return an empty recordset, no error is triggered and catch block is never executed.


USE master

      @StopWordListID int 
      , @SearchString varchar(1000) 
      , @WordBreakerLcid int 
      , @AccentSensitivity bit

      @SearchString = '"Introduction" OR "Repair and Service'
      , @WordBreakerLcid = 1033 -- English word breaker 
      , @AccentSensitivity = 0 -- Default is not accent sensitive

      @StopWordListID = ft.stoplist_id 
FROM    AdventureWorks2008.sys.tables t 
      INNER JOIN AdventureWorks2008.sys.fulltext_indexes ft ON ( t.object_id = ft.object_id ) 
WHERE   ( t.name = 'Document' )

        , LEFT ( dfp.special_term , 200 ) 
    FROM  AdventureWorks2008.sys.dm_fts_parser ( @SearchString , @WordBreakerLcid , @StopWordListID , @AccentSensitivity ) dfp
    PRINT 'Ok'
    PRINT 'Error'


Getting Exception info from catch block to Application_Error event of HttpModule


I need some help regarding one issue I am facing. I created a httpmodule for hadling the unhandled errors and I need to log those errors using log 4 net in database.

Everting working fine but I am not getting any error information once the error was hadled and I need that info too. I want to make it as a centralize module which can trap all errors and log those errors.

How call application_error event of httpmodule from catch block...so that I can log that info there and I no need log in every catch block..


Measure question - my desired size changes but parent controls don't catch an ondesired size change


I have an items presenter that contains expanders.  (In order to debug the events, I have a custom items presenter class with an OnChildDesiredSizeChanged event that does nothing more than base.OnChildDesiredEvent.  That way I can debug what I am really working on.

I have a custom expander class that I want to have change its desired size when it is collapsed.  The frustrating thing about expander is that they will update a desired size when you expand, but not when you collapse it.  So I have a custom expander class with my own on collapse event.  The idea is to remeasure the expander.  I had thought that doing so would cause it to notify parents that its desired size changed like what already happens when we expand.

So here is the collapse handler in my custom expander.

protected override void OnCollapsed()
			UIElement hdr = Header as UIElement;
			if (hdr != null)

Debugging I can see the desired size get smaller before and after I call measure.  So my desired size propert

How to Add a Send Activity in a Workflow Service try/catch catch block?


For a Workflow Service that has ReceiveRequest/SendResponse Activities, you can right click on the ReceiveRequest Activity a do a Create SendReply to add multiple SendResponse Activities. 

The problem is that I want to have a Try/Catch block in the Workflow Service.  This way when a fault occurs, I want to log the exception in my database and then use a Send or a SendResponse Activity to send the fault information back to the caller of the workflow service.

Bottom line is that VS2010 does not allow me to add an additional SendReply Activity inside the catch block.

Do you know how to do this?


Leo Cono, http://www.YouLoveMe.com - Free Dating


Why is Thread.Sleep() not interruped when it is in catch block?


Take a look at following simple code..
(This program is not meant to do some useful things. It's just for a demonstration purpose.)

class Program {
    private static void Main(string[] args) {
        // start new thread.
        Thread thread = new Thread(new ThreadStart(ThreadFunc));
        thread.IsBackground = false;

        // interrupt the thread.

    private static void ThreadFunc() {
        try {
            try {
                // assume something goes wrong...
                throw new Exception("TEST");
            catch (Exception) {

try catch question


right now I have this:

<%@ Page Language="vb" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strPage As String = ""
        Dim semiPos As Integer
        strPage = Request.Url.AbsoluteUri
        semiPos = InStr(strPage, ";")
        strPage = strPage.Substring(semiPos, strPage.Length - semiPos).Replace("http://", "")
        strPage = strPage.Substring(InStr(strPage, "/"), strPage.Length - InStr(strPage, "/"))
        If strPage.Contains("/") = False Then
            Dim pagepath As String = String.Empty
                pagepath = MapPath("/redirect/" & strPage & ".html")
            Catch ex As Exception

MVC architecture in ASP.Net using C# and Microsoft Data Access Application block

The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes [Burbeck92]:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

Some basic MVC question

  1. In regular asp net I can run (debug) the application but I can either "view in browser" that gives me the option to view the application and write code on same time.

In MVC I can't find this option.

  1. What is the basic DATA MODEL for working with SQL DB.

I mean with no any framework (entity framework, Sub sonic, Link to SQL etc')

I look for basic application that works with data but with no fw.

  1. What is the popular DB framework that working with data.
  2.  I am looking on  mvc series


C# Soup To Nuts  (the best series ever)


I watch some of the MVC video, seems that the music store is good but I have to wait to the other part.

Does any one know and recommend   a Microsoft MVC tutorial?





Web Site to Web Application Question


I've been building web sites and for my next project I will be creating a web application.  I use a 'BasePage' class in all my projects but, since web applications do not contain the 'App_Code' folder, what is the best place/practice for the 'BasePage' class?



connection string question from a newbie


when publishing  in the webmatrix dialogue it asks for "destination connection string" for my "database.mdf"

I was not sure what it was so I pasted this from my web.config file :

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True

it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue.

My question is this, What should go in the field for "Destination connection string"

Security Question Answer Retrieval


I know there is a method built in for retrieving the encrypted password, but how do I retrieve the encrypted security answer?

What I want to do is have a member profile update screen that the end user can update their password and security question and answer. However, when they get to this page, I want to already be showing the security question (the easy part) and its answer (the not so easy part).

I have updated web.config with passwordFormat=Encrypted and have added a machineKey with the generator (forgot the link, but located on eggheadcafe somewhere).

I haven't done ANYTHING yet, since I already have a user store with hashed information. I wanted to get some functionality done before publishing, wiping the store and recreating users (only a couple developers).


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend