Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2004, 02:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default TRY CATCH THROW question

I have a question regarding the syntax within a TRY CATCH statement where
in the CATCH section I am needing to THROW this error to the UI class and
handle error there via a MESSAGE BOX of some sort. My UI class
instantiates this class that makes a call to the webservice where I am
trying to autheticate a user who's already logged into my application but
the application timed out on them and logged them out. Any suggestions on
how to handle this better or direction would be appreciated. Thank you.

Here is my code:

// Constructor
public InvoiceList(int aintClientID, int aintMonthText, int aintYearText,
string usersToken)
{
iintClientid = aintClientID;
iintMonth = aintMonthText;
iintYear = aintYearText;

// Connect to the PSS_WebService.
Billing.Service1 wsSearch = new Billing.Service1();
wsSearch.Credentials = CredentialCache.DefaultCredentials;

// Define the dataset for this class.
idsInvoices = new DataSet();
idsInvoices.Locale = CultureInfo.InvariantCulture;

// Try-Catch Code when calling the WEBSERVICE :
try
{
idsInvoices = wsSearch.Invoices( iintClientid, iintMonth, iintYear,
usersToken );
}
catch (SoapException soapEx)
{
throw // WHAT DO I PUT HERE TO THROW TO ANOTHER CLASS? My other class is INVOICELIST.cs
}
 
Old July 1st, 2004, 03:54 PM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

throw new Exception(); would work but you would probably want to make a new class that inherits from Exception so that you will know in the other class what exception has been thrown.

catch(Exception ex)
{
  throw new LoginException(intClientid);
}

where

class LoginException : Exception
{
  public LoginException(Object sender, EventArgs e):base(sender,e){}
}


Is this what you wanted... if not maybe you could explain it a little better. Hope it helps.


www.CoderForRent.com
Get A Computer Job!





Similar Threads
Thread Thread Starter Forum Replies Last Post
throw an exception in catch Muyavil Java Basics 3 April 11th, 2009 10:56 PM
Try...Catch lowell VB.NET 3 July 23rd, 2007 06:35 AM
Ch 2 pg 70: links throw error subgenius BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 August 16th, 2004 05:26 PM
how to pass multiple values throw url class object kfarooq Servlets 1 June 20th, 2003 04:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.