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

  • Thread starter Thread starter Julia
  • Start date Start date
J

Julia

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
JuliaSystemException

and than declare a abase exception for each component?

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

MailSenderException:JuliaSystemException

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

FailedToConnectException:MailSenderException





Thanks.
 
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(JuliaSystemException exception)
{
Log(e)
}
catch(System.Exception exception)
{
MessageBox(e.message)
}
 
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
 
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
JuliaSystemException

and than declare a abase exception for each component?

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

MailSenderException:JuliaSystemException

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

FailedToConnectException:MailSenderException
 
Yes, you should be able to do that.

System.Exception 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(SerializationInfo info, StreamingContext 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(filename, FileMode.Create, FileAccess.Write);
// new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
// .Serialize(s, instance);
// s.Close();
// }
//
// public static object Deserialize ( string filename )
// {
// Stream s = new FileStream(filename, FileMode.Open);
// object o = new
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
// .Deserialize(s);
// s.Close();
// return o;
// }
 

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

Back
Top