dcsimg
Design question: using your own exceptions in JavaMail
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rizwan_Sattar
Posted On:   Wednesday, July 18, 2001 12:10 PM

Hey all, this is a design question, but one that I am having trouble with. I have been writing a new e-mail client using JavaMail and IMAP. Now, the client accesses mail services through an interface. In an implementation of that interface, all JavaMail actions are performed. Since methods in JavaMail raise all kinds of exceptions, I want to shield the client from them and produce simpler exceptions. Should I have try-catch clauses running rampant for each time I need to catch an exception in a method, or should I just have a: public void doSomethingInMessage() throws MyOwnException { try{ .... .... .... } catch (Exception A) { throw MyOwnException();    More>>

Hey all,


this is a design question, but one that I am having trouble with. I have been writing a new e-mail client using JavaMail and IMAP. Now, the client accesses mail services through an interface. In an implementation of that interface, all JavaMail actions are performed.


Since methods in JavaMail raise all kinds of exceptions, I want to shield the client from them and produce simpler exceptions. Should I have try-catch clauses running rampant for each time I need to catch an exception in a method, or should I just have a:

			
public void doSomethingInMessage() throws MyOwnException {
try{
....
....
....
} catch (Exception A) {
throw MyOwnException();
} catch (Exception B) {
throw MyOwnException();
} ....
}
}

or should i make it more specific to each thing called in the method? LIke:
			
public void doSomethingInMessage() throws MyOwnException {
try{
.... // throwable
} catch (Exception A) {
throw MyOwnException();
}

....

try {
.... // throwable
} catch (Exception B) {
throw MyOwnException();


....

}

or i could just hve it all in one BIG try-catch clause that catches all Exceptions... what do you think?


regards,

Rizwan

   <<Less

Re: Design question: using your own exceptions in JavaMail

Posted By:   Cory_Powers  
Posted On:   Thursday, July 19, 2001 05:37 AM

Personally I like to report back to the user as much information about why the error occured. So, I use a large try block if the exceptions that are thrown within that block are unique. i.e.

public void method() throws MyException{
try{
login();
databaseQuery();
}catch(LoginException a{
throw new MyException("Login Error", a);
}catch(SQLException b){
throw new MyException("Database Error", b);
}
}


If I have multiple functions with in a block that throw the same exception for different tasks I enclose each in a seperate try block. i.e.


public void method() throws MyException{
try{
databaseDelete();
}catch(SQLException a{
throw new MyException("Error Deleting Item", a);
}
try{
databaseQuery();
}catch(SQLException a){
throw new MyException("Error querying DB", a);
}
}


That way I can provide as much specific information to the user as possible.

Re: Design question: using your own exceptions in JavaMail

Posted By:   Rizwan_Sattar  
Posted On:   Wednesday, July 18, 2001 12:34 PM

In any case, would it be good idea to chain the exceptions?

Like:

} catch (Exception A) {
throw MyOwnException(msg, A);
}

regards,

rizwan
About | Sitemap | Contact