473,796 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Own exception class - plus in typename???

Hello everybody,

I've created for one of my classes a exception class derivated from
System.Exceptio n. This exception class is public and lies within my
class as inner class.

When I throw this exception I can't catch it with its name! When I try
to catch it with it's name then the catch-block will be ignored.... So
I've made a general catch with System.Exceptio n and printed the
runtime type...

....
catch (Exception ex)
{
Console.WriteLi ne(ex.getType() );
}
....

To my surprise the I've got the following typename:
namespace.outer _classname+owne xception_classn ame

What is this plus in the typename? I've never seen this bevore... Am I
doing something wrong? Or is there a trick to catch exceptions of this
type?

Help would be appreciated

Michael Wisheu
Dec 29 '07 #1
4 1509
mi*****@wisheu. eu wrote:
I've created for one of my classes a exception class derivated from
System.Exceptio n. This exception class is public and lies within my
class as inner class.

When I throw this exception I can't catch it with its name! When I try
to catch it with it's name then the catch-block will be ignored.... So
I've made a general catch with System.Exceptio n and printed the
runtime type...

...
catch (Exception ex)
{
Console.WriteLi ne(ex.getType() );
}
...

To my surprise the I've got the following typename:
namespace.outer _classname+owne xception_classn ame

What is this plus in the typename? I've never seen this bevore... Am I
doing something wrong? Or is there a trick to catch exceptions of this
type?
catch(outer_cla ssname.ownexcep tion_classname ex)

or

catch(namespace .outer_classnam e.ownexception_ classname ex)

is probably what you are looking for.

Arne

Dec 29 '07 #2
mi*****@wisheu. eu wrote:
I've created for one of my classes a exception class derivated from
System.Exceptio n. This exception class is public and lies within my
class as inner class.

When I throw this exception I can't catch it with its name! When I try
to catch it with it's name then the catch-block will be ignored.... So
I've made a general catch with System.Exceptio n and printed the
runtime type...

...
catch (Exception ex)
{
Console.WriteLi ne(ex.getType() );
}
...

To my surprise the I've got the following typename:
namespace.outer _classname+owne xception_classn ame

What is this plus in the typename? I've never seen this bevore... Am I
doing something wrong? Or is there a trick to catch exceptions of this
type?
And regarding the plus: see
http://msdn2.microsoft.com/en-us/library/w3f99sx1.aspx
(go down to th etable with "Delimiter Meaning").

Arne
Dec 29 '07 #3
<mi*****@wisheu .euwrote:
I've created for one of my classes a exception class derivated from
System.Exceptio n. This exception class is public and lies within my
class as inner class.

When I throw this exception I can't catch it with its name! When I try
to catch it with it's name then the catch-block will be ignored..
No, it won't - not if you use the correct type name. Is your type name
one which is also available not as a nested class? If so, it's probably
trying to catch that instead.

The "+" is just what the CLR uses to identify nested clases.

If that doesn't help, could you post a short but complete program which
demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 29 '07 #4
Thanks folks for your support!

I've NOW know that the plus stands for an inner class. But this wasn't
the problem... When you have several inner exception classes and you
program after 9pm then you should really look twice if you're really
catching the right exception...

Ín my case I wanted to catch the right exception but I haven't
administratrive privileges (Vista and it's lovely UAC) and another
inner exception was raised before. And this one wasn't catched!

It seems that is time to go to bed now... Thanks for all your help and
sorry for this silly help request.

Best regards

Michael
Dec 29 '07 #5

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

Similar topics

12
3699
by: Ritz, Bruno | last post by:
hi in java i found that when a method has a throws clause in the definition, callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the caller by specifying a throws clause as well. is there a similar machanism in c++? i want to force a developer to write handlers for all possible exceptions a method of my class library can throw.
4
31580
by: Steve | last post by:
I'll be the first to admit, I'm not entirely clear on the appropriate usage of either. From what I am reading in my books, a Struct and a Class are pretty much the same, with the difference being, a Class can have private and protected members, but a Struct everything is Public by default. I laymans terms what would be an appropriate reason to choose a Struct over a Class? So why would one want to choose a Class over a Struct.
7
2327
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding Herb Sutter's idiom of implementation of operator= via nonthrowing swap() member function, to guarantee strict exception safety. The idea of the idiom is shown by the example: -- code fragment 1 ---------------------------------------------------- class MyClass
13
5082
by: Mike Austin | last post by:
Hi all. Just working on a small virtual machine, and thought about using vector iterators instead of pointer arithmetic. Question is, why does an iterator plus any number out of range not generate a out_of_range exception? Maybe this is a gcc issue? I'm using gcc version 3.3.3 (cygwin special). Here's the full sample code: #include <iostream>
4
2044
by: Rob Richardson | last post by:
Greetings! I am working on an application that targets a Pocket PC running Windows CE and SQL Server CE. Almost all functions in the application use a Try block with a Catch block that looks like this: Try TryToDoIt() Catch e as Exception LogTheError(e)
3
2128
by: Nindi73 | last post by:
Hi, I am in need of a deep copy smart pointer (Boost doesn't provide one) which doesnt require the contained types to have a virtual copy constructor. I wrote a smart pointer class that I think meets these requirements, but after reading the chapter on exceptions in 'Exceptional C++':Sutter, I am not sure if its is really Exception safe or Exception Neutral. I suppose putting the theory in that chapter into practice isn't trivial.
2
1898
by: Dom Jackson | last post by:
Hello - I have a problem where I need to test some numeric code using a variety of built-in integer types: obj_type1 = obj_type2 OP obj_type3; // is obj_type1 correct? If I test with 10 built-in integer types, then I get 1000 permutations of the above statement. If I then test a dozen different operators, I get over 10,000 test operations.
1
1323
by: alan | last post by:
I have a set of classes, cell, cell_body, and cell_internal. cell_internal is an abstract base class, intended to encapsulate deferred computation. cell is just a wrapped pointer around cell_body; this is the user's interface to this code. When a cell is created, it creates a cell_body and attaches a shared_ptr member (value_) to the body. This shared_ptr should never be changed; the cell can only have one cell_body during its...
6
391
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
10457
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.