Own exception class - plus in typename???

M

michael

Hello everybody,

I've created for one of my classes a exception class derivated from
System.Exception. 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.Exception and printed the
runtime type...

....
catch (Exception ex)
{
Console.WriteLine(ex.getType());
}
....

To my surprise the I've got the following typename:
namespace.outer_classname+ownexception_classname

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
 
A

Arne Vajhøj

I've created for one of my classes a exception class derivated from
System.Exception. 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.Exception and printed the
runtime type...

...
catch (Exception ex)
{
Console.WriteLine(ex.getType());
}
...

To my surprise the I've got the following typename:
namespace.outer_classname+ownexception_classname

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_classname.ownexception_classname ex)

or

catch(namespace.outer_classname.ownexception_classname ex)

is probably what you are looking for.

Arne
 
A

Arne Vajhøj

I've created for one of my classes a exception class derivated from
System.Exception. 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.Exception and printed the
runtime type...

...
catch (Exception ex)
{
Console.WriteLine(ex.getType());
}
...

To my surprise the I've got the following typename:
namespace.outer_classname+ownexception_classname

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
 
J

Jon Skeet [C# MVP]

I've created for one of my classes a exception class derivated from
System.Exception. 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.
 
M

michael

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top