473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it good a approach to derive each exception from my base exception?


Hi I have a system which composed from 2 different components

1.MailSender

2.MailReciever

the Name of my system is JuliaSystem

I wonder if it is a good approach to derive all my custom exceptions from
JuliaSystemExce ption

and than declare a abase exception for each component?

for example for the mail sender I will have a base exception like the
following

MailSenderExcep tion:JuliaSyste mException

for specific exception of the mail sender I will do the following

FailedToConnect Exception:MailS enderException

Thanks.
Nov 16 '05 #1
7 1333
Why not just use one of the framework's inbuilt exceptions?

"Julia" wrote:

Hi I have a system which composed from 2 different components

1.MailSender

2.MailReciever

the Name of my system is JuliaSystem

I wonder if it is a good approach to derive all my custom exceptions from
JuliaSystemExce ption

and than declare a abase exception for each component?

for example for the mail sender I will have a base exception like the
following

MailSenderExcep tion:JuliaSyste mException

for specific exception of the mail sender I will do the following

FailedToConnect Exception:MailS enderException

Thanks.

Nov 16 '05 #2
Because i will be able to catch(if i want) all exceptions generated by my
system in a single place
and other in a second place
catch(JuliaSyst emException exception)
{
Log(e)
}
catch(System.Ex ception exception)
{
MessageBox(e.me ssage)
}

"Bonj" <Bo**@discussio ns.microsoft.co m> wrote in message
news:1D******** *************** ***********@mic rosoft.com...
Why not just use one of the framework's inbuilt exceptions?

"Julia" wrote:

Hi I have a system which composed from 2 different components

1.MailSender

2.MailReciever

the Name of my system is JuliaSystem

I wonder if it is a good approach to derive all my custom exceptions from JuliaSystemExce ption

and than declare a abase exception for each component?

for example for the mail sender I will have a base exception like the
following

MailSenderExcep tion:JuliaSyste mException

for specific exception of the mail sender I will do the following

FailedToConnect Exception:MailS enderException

Thanks.

Nov 16 '05 #3
Then, it is probably a good approach.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Julia" <co********@012 .net.il> wrote in message
news:u6******** ******@TK2MSFTN GP14.phx.gbl...
Because i will be able to catch(if i want) all exceptions generated by my
system in a single place
and other in a second place
catch(JuliaSyst emException exception)
{
Log(e)
}
catch(System.Ex ception exception)
{
MessageBox(e.me ssage)
}

"Bonj" <Bo**@discussio ns.microsoft.co m> wrote in message
news:1D******** *************** ***********@mic rosoft.com...
Why not just use one of the framework's inbuilt exceptions?

"Julia" wrote:
>
> Hi I have a system which composed from 2 different components
>
> 1.MailSender
>
> 2.MailReciever
>
>
>
> the Name of my system is JuliaSystem
>
> I wonder if it is a good approach to derive all my custom exceptions from > JuliaSystemExce ption
>
> and than declare a abase exception for each component?
>
> for example for the mail sender I will have a base exception like the
> following
>
> MailSenderExcep tion:JuliaSyste mException
>
> for specific exception of the mail sender I will do the following
>
> FailedToConnect Exception:MailS enderException
>
>
>
>
>
> Thanks.
>
>
>


Nov 16 '05 #4
Thanks,
What about serialization, can I serialize an exception including all sub
inner exceptions?
I read some articles regarding permissions and security but I am not sure I
understood
what they talk about

Thanks

"Dennis Myrén" <de****@oslokb. no> wrote in message
news:WD******** **********@news 4.e.nsc.no...
Then, it is probably a good approach.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Julia" <co********@012 .net.il> wrote in message
news:u6******** ******@TK2MSFTN GP14.phx.gbl...
Because i will be able to catch(if i want) all exceptions generated by my system in a single place
and other in a second place
catch(JuliaSyst emException exception)
{
Log(e)
}
catch(System.Ex ception exception)
{
MessageBox(e.me ssage)
}

"Bonj" <Bo**@discussio ns.microsoft.co m> wrote in message
news:1D******** *************** ***********@mic rosoft.com...
Why not just use one of the framework's inbuilt exceptions?

"Julia" wrote:

>
> Hi I have a system which composed from 2 different components
>
> 1.MailSender
>
> 2.MailReciever
>
>
>
> the Name of my system is JuliaSystem
>
> I wonder if it is a good approach to derive all my custom exceptions

from
> JuliaSystemExce ption
>
> and than declare a abase exception for each component?
>
> for example for the mail sender I will have a base exception like the
> following
>
> MailSenderExcep tion:JuliaSyste mException
>
> for specific exception of the mail sender I will do the following
>
> FailedToConnect Exception:MailS enderException
>
>
>
>
>
> Thanks.
>
>
>



Nov 16 '05 #5
This will allow you to handle your custom exceptions globally while not handling other system ones or other application ones that other components may throw application exceptions. If you want common data and facilities to be available in your application ceptions this is also a good idea. If you don't require either of these it doesn't really gain you anything (although its not a coist either apart from the extra source code you have to test and maintain).

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
Hi I have a system which composed from 2 different components

1.MailSender

2.MailReciever

the Name of my system is JuliaSystem

I wonder if it is a good approach to derive all my custom exceptions from
JuliaSystemExce ption

and than declare a abase exception for each component?

for example for the mail sender I will have a base exception like the
following

MailSenderExcep tion:JuliaSyste mException

for specific exception of the mail sender I will do the following

FailedToConnect Exception:MailS enderException

Nov 16 '05 #6
Yes, you should be able to do that.

System.Exceptio n is marked as Serializable, and it implements ISerializable.

You can use GetObjectData to serialize the Exception.

You can use the protected constructor with the signature:
protected Exception(Seria lizationInfo info, StreamingContex t context)
to deserialize the Exception object.

You should also be able to serialize/deserialize using something like these
simple functions:
//
// public static void Serialize ( object instance, string filename )
// {
// Stream s = new FileStream(file name, FileMode.Create , FileAccess.Writ e);
// new System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er()
// .Serialize(s, instance);
// s.Close();
// }
//
// public static object Deserialize ( string filename )
// {
// Stream s = new FileStream(file name, FileMode.Open);
// object o = new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er()
// .Deserialize(s) ;
// s.Close();
// return o;
// }

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Julia" <co********@012 .net.il> wrote in message
news:eW******** ******@TK2MSFTN GP12.phx.gbl...
Thanks,
What about serialization, can I serialize an exception including all sub
inner exceptions?
I read some articles regarding permissions and security but I am not sure
I
understood
what they talk about

Thanks

"Dennis Myrén" <de****@oslokb. no> wrote in message
news:WD******** **********@news 4.e.nsc.no...
Then, it is probably a good approach.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Julia" <co********@012 .net.il> wrote in message
news:u6******** ******@TK2MSFTN GP14.phx.gbl...
> Because i will be able to catch(if i want) all exceptions generated by my > system in a single place
> and other in a second place
>
>
> catch(JuliaSyst emException exception)
> {
> Log(e)
> }
> catch(System.Ex ception exception)
> {
> MessageBox(e.me ssage)
> }
>
>
>
> "Bonj" <Bo**@discussio ns.microsoft.co m> wrote in message
> news:1D******** *************** ***********@mic rosoft.com...
>> Why not just use one of the framework's inbuilt exceptions?
>>
>> "Julia" wrote:
>>
>> >
>> > Hi I have a system which composed from 2 different components
>> >
>> > 1.MailSender
>> >
>> > 2.MailReciever
>> >
>> >
>> >
>> > the Name of my system is JuliaSystem
>> >
>> > I wonder if it is a good approach to derive all my custom exceptions
> from
>> > JuliaSystemExce ption
>> >
>> > and than declare a abase exception for each component?
>> >
>> > for example for the mail sender I will have a base exception like
>> > the
>> > following
>> >
>> > MailSenderExcep tion:JuliaSyste mException
>> >
>> > for specific exception of the mail sender I will do the following
>> >
>> > FailedToConnect Exception:MailS enderException
>> >
>> >
>> >
>> >
>> >
>> > Thanks.
>> >
>> >
>> >
>
>



Nov 16 '05 #7
Hi,

Take a look at this thread:
http://groups.google.com/groups?hl=e...ublic.dotnet.*

You will find there a couple of good links, especially this
http://blogs.msdn.com/brada/archive/.../25/96251.aspx

in short it recommend that you keep your exception hierarchy wide and not
deep, a very interesting reading.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Julia" <co********@012 .net.il> wrote in message
news:eM******** ******@TK2MSFTN GP15.phx.gbl...

Hi I have a system which composed from 2 different components

1.MailSender

2.MailReciever

the Name of my system is JuliaSystem

I wonder if it is a good approach to derive all my custom exceptions from
JuliaSystemExce ption

and than declare a abase exception for each component?

for example for the mail sender I will have a base exception like the
following

MailSenderExcep tion:JuliaSyste mException

for specific exception of the mail sender I will do the following

FailedToConnect Exception:MailS enderException

Thanks.

Nov 16 '05 #8

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

Similar topics

12
1871
by: Ferdi Smit | last post by:
I wanted to provide a template class with an optional data member. The most natural way to do this was to implement a member for a given template parameter, and in the case of 'void', then not. I came up with the following, and I'm wondering if the design is any good. Perhaps I'm overcomplicating things? Or is it ok? // First we use a...
5
6741
by: p988 | last post by:
Could someone show me how to derive and use custom exception types separately from:System.Exception, System.Object and System.ApplicationException in C#? When people say:"Use Visual Studio .NET to create a component..." What does it mean by "component" here in C#?
2
1381
by: chris.millar | last post by:
The class below uses the switch clause in the GetXSLT method. I want it to code it with a more OO approach does anyone have any suggestions, or change to make. cheers using System; using System.Collections; using System.Configuration; using System.Data; using System.IO; using System.Xml;
2
1710
by: Locia | last post by:
Can I cast from base class to derive class? class A { } class B:A {
5
348
by: sherifffruitfly | last post by:
Hi, I'm just learning cpp, and the exercise I'm working on is basically as follows: 1) Create a struct type with 4 members (char, char, char, int). 2) Create an array of, say 3 instances of the struct, and populate them with data. 3) cin 1, 2, 3, or 4 from the user 4) If the user selected, say, 2, display the contents of the 2nd data
3
1650
by: gyan | last post by:
Please go though following program: #include <iostream.h> class base { public: int basepublic; protected: int baseprotected; };
5
1590
by: The Cool Giraffe | last post by:
I'm designing an ABC and in connection to that i have run into some "huh!" and "oh...". Let me put it as a list. 1. Since the class will only contain bodies of the methods, only the header file is needed. There will be no definitions provided until i derive the ABC. True or false? 2. Since i'll have two different classes (both derived...
0
1061
by: purplepangolin | last post by:
I have a generic base class and need a list to contain different types of objects that derive from this. Public class genericBase<T> where T: ConfigBase{} I have tried : List<genericBase<ConfigBase>> _objectTypes but when I try to add to it using: ObjectTypes.Add((ObjectType<ObjectConfigBase>)UI);
23
3120
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object model: that most OO features are not available for class object design without loss of POD-ness. So, I'm more than leaning toward "bad" because of...
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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...
0
5219
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...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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...

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.