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

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

Add Release-Only try-catch to CLR languages

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
Deploying a software, it's a common practice to encapsulate top-most function calls and/or event handlers with general try-catch blocks to deliver an error description to the user instead of just having him/her see the software exiting unexpectedly when unexpected exceptions occur. Unfortunately, during debugging it is most annoying to reach these log entries or message boxes instead of having Visual Studio halt where the exception occured. At the time of writing it is possible to designate particular exception types to halt the debugger when they are actually thrown. But it becomes a nuisance when there are many exception types to be marked this way. Plus, it becomes contra-productive if there is a scenario when expected exceptions of the marked types occur regularly and "Continue" has to be selected again and again in the debugger. Thus, I'd like to suggest to add a new, Microsoft specific, "try" keyword to all of the CLR languages (plus C++), perhaps something like "__try". This new kind of try should create a try-catch block only when compiling in Release mode. (This behaviour might apply to other configurations as well. I suppose the Configuration Settings dialog to provide an additional checkbox column to provide an option to select whether a particular configuration will create a try-catch block or not.)   See here for

View Complete Post

More Related Resource Links

WPF XBAP Release Doesn't Throw/Catch Errors


On my development box, launching the XBAP in either Debug or Release with Visual Studio 2010... it throws and catches errors just fine.  So I published the app to be hosted on our Win2008 R2 server...  Now here is what is wierd.  On my machine, hitting the published app still throws/catches errors just fine.  But on other users workstations, it just locks up IE for them, no error, no eventvwr message, nothing.

Any ideas?

Thanks a lot!!!



In App.xaml.cs I am catching all unhandled exceptions this way:

  public partial class App : Application
    protected override void OnStartup(StartupEventArgs e)
      Application.Current.DispatcherUnhandledException += AppDispatcherUnhandledException;
    protected void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
      e.Handled = true;
    protected static void HandleException(Exception ex)
      ErrorWindow errorWindow = new ErrorWindow("Error connecting to servers, please try reloading the page!", ex, false);

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:

reader.getordinal("column_may_not_exist") how to catch the exception?



would any body please help me to catch the exception if the column doesnot exist as my table columns are not static.

sometimes its throwing me indexoutofrange exception as the column doesnot exist

thanks for the help guys

Patterns in Practice: Internal Domain Specific Languages


Jeremy Miller explains how internal Domain Specific Languages can help you craft code that is easier to read and write. His bag of tricks to improve your programming includes extension methods, fluent interfaces, object extensions and use of the semantic model.

Jeremy Miller

MSDN Magazine January 2010

The Polyglot Programmer: Mixing And Matching Languages


See why you need to be a polyglot programmer and what mixing and matching languages can do for your projects.

Ted Neward

MSDN Magazine March 2009

Alphabet Soup: A Survey of .NET Languages And Paradigms


Here we present a rundown of the various language paradigms of CLR-based languages via short language introductions and code samples.

Joel Pobar

MSDN Magazine May 2008

Interview++: Bjarne Stroustrup on the Evolution of Languages


Howard Dierking talks to the inventor of C++, Bjarne Stroustrup, about language zealots, the evolution of programming, and what's in the future of programming.

Howard Dierking

MSDN Magazine April 2008

Editor's Note: A Large Release Wave is Headed your Way


This month Howard Dierking discusses the coverage of Windows Server 2008, SQL Server 2008, and Visual Studio 2008.

Howard Dierking

MSDN Magazine Launch 2008

CLR Inside Out: Dynamic Languages and Silverlight


DLRConsole gives you an interactive environment for playing with dynamic languages in Silverlight.

Jimmy Schementi

MSDN Magazine February 2008

SOAP Toolkit 2.0: New Definition Languages Expose Your COM Objects to SOAP Clients


In SOAP Toolkit 2.0, the Services Description Language (SDL) has been replaced with the Web Services Description Language (WSDL) and the Web Services Meta Language (WSML). WSDL and WSML files describe the interfaces to a service and expose COM objects to SOAP clients. This article describes a custom tool, IDL2SDL, which takes an IDL file and produces WSDL and WSML files without waiting for a DLL or TLB file to be generated. Also shown is a customized development environment in which WSDL and WSML files automatically reflect the changes to IDL files.

Carlos C. Tapang

MSDN Magazine April 2001

How to CATCH "Invalid postback or callback argument" exception?



How can I catch this exception? I do not want it to stop my page execution. Can/Should I do that?

Server Error in '/' Application.
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally

Using the BDC API how to catch the returned code when executing a stored procedure?

using BDC API, how can i catch the return code a stored procedure returns?

I tried Entity.Execute to execute a generic method. However, it returns an empty Entity table.

I know you can do it by setting up an output variable. I prefer returning an integer for tracking errors.

Any ideas?



Catch button click event in different .aspx page.


I have a button which starts processing.
I want that when ever a button is click from page1.aspx .. a count down timer should start and displayed on page2.aspx.
I am thinking of using iframe to join 2 pages.

Please let me know your suggestions.


Unable to catch WCF EndpointNotFound exception in SecurityToken.GetToken( . )

I have a set of WCF services that I am integrating with, I can not change them in any way because they are provided by a third party. I use a username/password scheme to authenticate with the services. If the services are not available I get an exception (EndPointNotFoundException) from the SecurityTokenProvider class that I can not catch. I understand why the exception is being thrown, I just need to know how I can handle it so that I can gracefully handle the errors in the user interface. Is there a way I can catch this exception or a better way to handle this scenario? The Exception The exception is thrown from System.IdentityModel.Selectors.SecurityTokenProvider : GetToken( TimeSpan timeout ) public SecurityToken GetToken(TimeSpan timeout) {    SecurityToken token = this.GetTokenCore(timeout);     if (token == null)    {        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.TokenProviderUnableToGetToken, this)));    }     return token;} The channel open part When I open the channel I have it wrapped in exception handling, but none of it seems to trap the SecurityToken exception. I am using the ExceptionHandlingProxyWrapperBase try{    this.Open();} catch( EndpointNotFoundException epnfe ){    // Handle the exception} catch( E

How to catch click from link inside widget

Hello,I have an ASP.NET (3.5) page. On the page there is a widget.  Here is the page code:<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Stiri.aspx.cs" Inherits="Stiri" Title="Stiri in Teleorman" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><script language="javascript" type="text/javascript" src="http://www.presaonline.com/ajx/webmasters/get/0/?tidings_number=5&show_image=on&show_body=on&show_county="></script></asp:Content> The widget (script) displays a list of news from another website like this:---------------------------------------------------------title1 (as link)short descriptiontitle2 short description.............................................---------------------------------------------------------1. When a user clicks on one of the links in the above list I want to "catch" the link.2. ISSUE: When the link (from the list) is clicked the URL is opened in another browser tab3. If a user clicks on a link I want to redirect him not to the link's URL but to a page of my website.I

RFC: I want your FB on "RS Parameters Enhancements" for the next major release

Hello,RS product team is looking into doing some substantive work in the next release of Reporting Services, related to enhancing parameters. This could include changes to RDL, design tools like BIDS and RB, SOAP API's, Report Manager and SharePoint UI's, and of course the Report Server internals. Without making any commitments, I'll just lob a few "top of the list" features out there to prime the pump:Prompt localizabilityValidation (value ranges, defining invalid values, extensible validation through assemblies, etc.)Tree view of heirarchical parametersHistory and Execution snapshot parameter controlSelect All configuration -- yes or no, top or bottom, etc.Multivalue usabilityPLZ reply to this thread with your "wish list" for better RS parameters. I'd also very much like to see sample reports that use parameters in creative ways, especially if you had to do extra work to compensate for missing features or unexepected behaviors. I'll take all the FB, filter it through the list we already have, and hopefully come up with a list of features we can pull off in time for the next major release that meets as much of your needs as possible.Thanks for your consideration, and regards.Mike

Catch Block question

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