473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Inner exception

Hi,

Is it possible to find out if an exception has an inner exception or not.

for example if I catch an exception of type "System.Web.HttpException"

it is likely (but not definate) that the error conatians an inner exception.

what I would like to do is determine if the exception has an inner exception
and the act on it.
I don't just want to call innerexception because I am assuming another
exception will be thrown if an inner exception does not exist.

thanks in advance for your help.

cheers

martin.


Nov 18 '05 #1
2 2953
You can catch the "outer"/ main exception and then check its inner exception property like so
[C#
if(ex.InnerException != null
Response.Write(ex.InnerException.ToString())

Here are complete code samples

[C#
private void Page_Load(object sender, System.EventArgs e

tr

Method1();
}
catch(Exception ex

if(ex.InnerException != null
Response.Write(ex.InnerException.ToString())
}
void Method1(

tr

Method2();
}
catch(Exception e

throw new Exception("E2", e)
}
void Method2(

throw new Exception("E1");
[Visual Basic
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Tr
Method1(
Catch ex As Exceptio
If Not ex.InnerException Is Nothing The
Response.Write(ex.InnerException.ToString()
End If
End Try
End Su

Function Method1(
Tr
Method2(
Catch e As Exceptio
Throw New Exception("E2", e
End Try
End Function

Function Method2(
Throw New Exception("E1"
End Functio

===========
Rasika Wijayaratn

Nov 18 '05 #2
Thank you
"Rasika Wijayaratne" <ra**********@luckymail.com> wrote in message
news:0E**********************************@microsof t.com...
You can catch the "outer"/ main exception and then check its inner exception property like so: [C#]
if(ex.InnerException != null)
Response.Write(ex.InnerException.ToString());
Here are complete code samples:

[C#]
private void Page_Load(object sender, System.EventArgs e)
{
try
{
Method1();
}
catch(Exception ex)
{
if(ex.InnerException != null)
Response.Write(ex.InnerException.ToString());
}
}

void Method1()
{
try
{
Method2();
}
catch(Exception e)
{
throw new Exception("E2", e);
}
}

void Method2()
{
throw new Exception("E1");
}
[Visual Basic]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try
Method1()
Catch ex As Exception
If Not ex.InnerException Is Nothing Then
Response.Write(ex.InnerException.ToString())
End If
End Try
End Sub

Function Method1()
Try
Method2()
Catch e As Exception
Throw New Exception("E2", e)
End Try
End Function

Function Method2()
Throw New Exception("E1")
End Function

============
Rasika Wijayaratne

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Murat Tasan | last post by:
i have an inner class and an outer class, both of which have an identically named member. how from the inner class can i reference the outer member? (the example code should illustrate this...
5
by: Pekka Niiranen | last post by:
Hi, I have Perl code looping thru lines in the file: line: while (<INFILE>) { ... $_ = do something ... if (/#START/) { # Start inner loop
7
by: Kenny Cutter | last post by:
Hi group, I am quite new to exceptions in .NET and I am a bit confused of how to use the inner exceptions. Could anyone explain? Let's say I have a function that takes a double (X) that is not...
4
by: PASQUALE | last post by:
Hi I have a question: do the both statements below give the same result? If yes then does somebody know something about preformance differencies using these joins? SELECT A.* FROM Table1 A...
1
by: stuart | last post by:
Hi, Is it possible to find out if an exception has an inner exception or not. for example if I catch an exception of type "System.Web.HttpException" it is likely (but not definate) that the...
2
by: a_newcomb | last post by:
I am using a HttpWebRequest object to a custom webhandler. When processing the request on the server side, I need to return exceptions to the web request. Whenever the exceptions are thrown, web...
2
by: Sue | last post by:
I've got a simple Application_OnError routine set up as a generic error trap for web applications running on IIS server (VS 2003) that logs error info and the text of the first inner exception....
9
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added...
6
by: Lance | last post by:
hi all, using the following code, i never get a message box showing the error, but the default error sound is produced (like there should be an accompanying messagebox). \\\\\\\\\\ Dim FI As...
5
by: Thomas Guettler | last post by:
Hi, How can you get the traceback of the inner exception? try: try: import does_not_exit except ImportError: raise Exception("something wrong") except:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.