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


Top 5 Contributors of the Month
david stephan
Santhakumar Munuswamy
Asad Ali
Fauzul Azmi
Post New Web Links

Throw Vs Throw(ex)

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application
 

whta is the difference between Throw and Throw(ex).. which to prefere in which case




View Complete Post


More Related Resource Links

{ End Bracket }: Don't Be Afraid To Throw Away Your Work

  

With today's processing power at your disposal, Josh Phillips recommends speculative computation-performing operations ahead of time even if you may never need the results.

Josh Phillips

MSDN Magazine October 2008


AsyncFileUpload: Throw Error on image size

  

I have an AsyncFilUpload that is used to upload  to my site. On the server side I have code that checks the width and height of the image and will only save the image if it is within the limits buit I can't figure out how to get the AsyncFileUpload control to show an error when this happens. Can anyone give me any pointers?

 


PresentationHost.exe throw error: C Run-Time Error R6034

  
Hello, we are hosting one of our WPF (.NET 3.5 SP1) components within XBAP and thus it delivered through browser (explorer 8.0) to client. Some time clients (running explorer) receive error and this error thrown by presentetionhost.exe. The error is: C Run-Time Error R6034. We looked the error in forums and it appears related to manifest. But manifest exists for that WPF/XBAP application. Furthermore, the error does not occurs always only sometime and it not consistent it cannot be recreated on same machine for same scenario. Cleaning online app cache with mage.exe -cc does not resolve issue it continue to appear occasionally. Some comment: 1. it seems only appear at client machines, no evidence it appeared at developers machines. 2. Sometime application continues working after error box closed, but sometime it crushes. 3. May be it is not relevant but, the application accessing server side with WCF, but no error in this area. Does someone have ideas how to get rid of the error? Thanks, Pavel

Creating database throw exception!

  
When running SQL commands, it throws error information. Why is it? My env :    windows server 2003 64bit     sql server 2008 . Command :   CREATE DATABASE [AdventureWorks2009]     ON (NAME = 'AdventureWorks2009_Data', FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks2009_Data.mdf', SIZE = 170, FILEGROWTH = 8),     FILEGROUP DocumentFileStreamGroup CONTAINS FILESTREAM ( NAME = FileStreamDocuments, FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Documents')     LOG ON (NAME = 'AdventureWorks2009_Log', FILENAME = N'E:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks2009_Log.ldf' , SIZE = 2, FILEGROWTH = 96); GO     Error information:   Msg 5120, Level 16, State 106, Line 1 Unable to open the physical file "E:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Documents". perating system error -2147024891: "0x80070005(failed to retrieve text for this error. Reason: 1815)".

How to access Macros in excel throw DotNet

  
Hi I want to use Macros in Excel throw DotNet. Give simple examples. Can you please any body, give some ideas.   thanks in advance. 

iterate throw rows of Template Column in Datagrid

  

Hi

I am using WPF DataGrid (VS 2008). i am using Template column with a button in it i want to change the content of the button(Caption) when it is clicked .i am doing it in its click event ,but it  changes the content of only the button clicked(only one row). i want to change the content of button in all rows.

how can access the button instance of all rows in this template column.

Regards:

Naseer


I created a new control and im drawing some lines and points inside but the form1 designer throw me

  

This is the code of the control:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace My_Diet_Control
{
    public partial class My_Diet_Graph_Control : UserControl
    {
        int x_axis_lenght;
        int y_axis_lenght;
        int marginLeft;
        int marginRight;
        int marginBottom;
        int marginTop;
        My_Diet_Graph_Control myControl1;
        Diet_Data myData;
        public My_Diet_Graph_Control()
        {
            InitializeComponent();
        }

        private void My_Diet_Graph_Control_Load(object sender, EventArgs e)
      &nbs

Is there any way to get the Transfer SQL Server Objects Task to not throw error if an object already

  

I've asked this before but never got an answer. Is there a way to configure the Transfer SQL Server Objects Task so that it will only transfer objects that don't already exist in the destination? Or to skip over objects that already exist?

I do not want to "roll my own". I want to use the task in order to save time.


PresentationHost.exe (XBAP) throw error: C Run-Time Error R6034

  

Hello,

we are hosting one of our WPF (.NET 3.5 SP1) components within XBAP and thus it delivered through browser (explorer 8.0) to client.
Some time clients (running explorer) receive error and this error thrown by presentetionhost.exe. The error is: C Run-Time Error R6034.
We looked the error in forums and it appears related to manifest. But manifest exists for that WPF/XBAP application. Furthermore, the error does not occurs always only sometime and it not consistent it cannot be recreated on same machine for same scenario.
Cleaning online app cache with mage.exe -cc does not resolve issue it continue to appear occasionally.

Some comment:
1. Sometime application continues working after error box closed, but sometime it crushes.
2. May be it is not relevant but, the application accessing server side with WCF, but no error in this area.
3. I read another thread of this forum: Deploying WPF app - runtime error R6034 (social.msdn.microsoft.com/Forums/?en-US/wpf/thread/233fee41-6cf9-40cd?-bf39-66ddade11746)
 and there the sxstrace tool in use, which in my case is not possible due XP OS.

Does someone have ideas how to get rid of the error?

Thanks, Pavel


throw exception message giving internal server error on live site

  

using vb.net/asp.net 2005

when a user enters a bad email I am doing a check on this and throwing an exception message as follows, this works fine on the test site but for some reason the same code on the live site gives a "internal server error" (http code 500).  The code below:

            If isThisEmailValid(strEmailThatTheUserEntered) Then
		'do something

            Else

                Throw New Exception("You entered a bad email address.")

            End If


not certain why this is happening, I assume that it's some server or config difference between the test and live sites.  has anyone seen this before?  For a quick fix i'm registering javascript alert and showing the same text so it works but I would like to figure out why the code above is not working.

as always, thanks for your feedback

MC


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

 

*EDIT*

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;
      base.OnStartup(e);
    }
    protected void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
      HandleException(e.Exception);
      e.Handled = true;
    }
    protected static void HandleException(Exception ex)
    {
      ErrorWindow errorWindow = new ErrorWindow("Error connecting to servers, please try reloading the page!", ex, false);
      ((Panel)WPFUtilities.GetApplicationLayoutRoot()).Children.Add(errorWindow);
    }
  }

JDBC - How can I get it to not throw an exception on ResultSet.isLast()?

  

Is there some way to configure the Sql Server JDBC driver, or parameters on the Connection or prepareStatement() so that ResultSet.isLast() can be called when I call a stored procedure that returns a ResultSet?

thanks - dave


Very funny video - What's your Metaphor?

When processing files recursively, why the top DirectoryInfo always throw a Exception?

  

hi

I have quite a simple app, which modify the CreationTime property of all the subfiles and subfolders in a folder, the code is like:

    void Mod(DirectoryInfo dir, DateTime time)
    {
      foreach (DirectoryInfo subDir in dir.GetDirectories())
        Mod(subDir, time);
      foreach (FileInfo fi in dir.GetFiles())
      {
        fi.CreationTime = time;
      }
      dir.CreationTime = time;
    }

I call this method with a folder like: C:\a\b, then all the subfiles and subfolders are correctly modified, but WHY I received an Exception: The process cannot access the file 'C:\a\b' because it is being used by another process.

I changed the folder to: C:\a, then C:\a\b was modified successfully, then I got an Exception:The process cannot access the file 'C:\a' because it is being used by another process.

thanks in advance.


throw and catch exception handling

  

Hi,

iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if  any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
                        int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
                        if (updaterec > 0)
                        {
                            running = true;
                            DataSet BillContainerDetails = BillingDetails();
         

SystemNetworkInterface.GetAdaptersAddresses throw exception

  

hi,

I got this exception:

Exception: System.Net.NetworkInformation.NetworkInformationException
Message: The handle is invalid

when the function SystemNetworkInterface.GetAdaptersAddresses is call the first time.

Call stack:

Source: System
   at System.Net.NetworkInformation.SystemNetworkInterface.GetAdaptersAddresses(AddressFamily family, FixedInfo fixedInfo)
   at System.Net.NetworkInformation.SystemNetworkInterface.PostWin2KGetNetworkInterfaces(AddressFamily family)
   at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces(AddressFamily family)
   at System.Net.NetworkInformation.SystemNetworkInterface.InternalGetIsNetworkAvailable()
   at System.Net.NetworkInformation.NetworkChange.AvailabilityChangeListener.ChangedAddress(Object sender, EventArgs eventArgs)
   at System.Net.NetworkInformation.NetworkChange.AddressChangeListener.AddressChangedCallback(Object stateObject, Boolean signaled)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

I'm using c# 3.5. The problem occurs on Windows 2008. Not on windows XP.

The network card is: Intel PRO 1000 MT Quad Port NIC.

How could I know the reason why the

Better way to throw FaultException?

  
if(_session==null)
{        
  var f = new CompanyFault("108EAB82-B6BC-4F0C-AFAF-784F8E64768A", "SessionFactory returned null when creating adminSession");
  Log.Error(f); //log4net
  throw new FaultException<CompanyFault>(f, f.Message, f.FaultCode);
}
[DataContract(Namespace = "http://company.no/services/faults")]
public class UserNotFoundFault : CompanyFault
{
  public UserNotFoundFault(string message)
    : base("3B421F5D-4817-486C-BC5F-FF25B9CB1008", message)
  {      
  }
}



Hi, this is my first post here :)

I have defined a class/FaultContract CompanyFault wich has two properties; Message and Faultcode (System.ServiceModel.FaultCode). Currently I use the above code where I create an instance of CompanyFault, log the fault with log4net wich knows what todo with CompanyFault, and finally throw an FaultException<CompanyFault> where I pass the faultcode and message from CompanyFault. 

My question is: Is there a better/smarter way to do this? Now I have to write 3 lines everytime I want to throw a FaultException and log it.. How do you organize FaultContracts and throw FaultExceptions?

EntityDataSource throw Exception when Update with Self-Reference

  

For a Table A defined in the DB like this:

A : { id, selfId, name, ... }

where selfId is a foreign key refered to Table A itself.

I generated the Entity automatically like this:

A : { string id; A self; string name, ... }

when i update the entity in gridview Edit/Update CommandField

i got the exception:

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be
Categories: 
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