Hriar,
You seem to have thrown this user exception properly from an architecure
poing of view. I see you have posted this to our public news forums as
well. This is best handled in a vendor forum to debug rather then
EJB-INTEREST. Ill repond on that forum.
Dave Wolf
Internet Applications Division
Sybase
----- Original Message -----
From: "Hrair Karaboyadjian" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, February 22, 2001 7:15 AM
> Hi, I have a question about Exception catching in EJB. How can I throw a
> custom Exception from my EJB?
> I created an Exception class that extends the java.lang.Exception and used
> it inside the EJB to throw Exception
> When I call my EJB from a bean requested from JSP file I get this error in
> the srv.log file,
>
> Feb 21 16:52:45 2001: SM
> Feb 21 16:52:45 2001: at
>
com.dcsoft.isppro.ServerManagerBean.vsAddServer(ServerManagerBean.java:152)
> Feb 21 16:52:45 2001: at
>
com.dcsoft.isppro._sk_DCSoft_ISPPro_ServerManager.invoke(_sk_DCSoft_ISPPro_S
> erverManager.java:166)
> Feb 21 16:52:45 2001: at com.sybase.CORBA.local.Socket.call(Native
Method)
> Feb 21 16:52:45 2001: at
> com.sybase.CORBA.local.OutputStream.write(OutputStream.java:29)
> Feb 21 16:52:45 2001: at
> com.sybase.CORBA.iiop.Connection.invoke(Connection.java:1947)
> Feb 21 16:52:45 2001: at
>
com.dcsoft.isppro.ServerManager_Stub.vsAddServer(ServerManager_Stub.java:44)
> Feb 21 16:52:45 2001: at
>
com.dcsoft.isppro.ServerManagerLoader.vsAddServer(ServerManagerLoader.java:9
> 6)
> Feb 21 16:52:45 2001: at
>
_0005cAddServerPrc_0002ejspAddServerPrc_jsp_35._jspService(_0005cAddServerPr
> c_0002ejspAddServerPrc_jsp_35.java:156)
> Feb 21 16:52:45 2001: at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:130)
> Feb 21 16:52:45 2001: at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> Feb 21 16:52:45 2001: at
>
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.ja
> va:164)
> Feb 21 16:52:45 2001: at
> org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:256)
> Feb 21 16:52:45 2001: at
> org.apache.jasper.runtime.JspServlet.service(JspServlet.java:361)
> Feb 21 16:52:45 2001: at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> Feb 21 16:52:45 2001: at
> com.sybase.jaguar.servlet.JagServlet.service(JagServlet.java:164)
> Feb 21 16:52:45 2001: at
>
com.sybase.jaguar.servlet.JagRequestDispatcher.service(JagRequestDispatcher.
> java:760)
> Feb 21 16:52:45 2001: at
> com.sybase.jaguar.servlet.ServletEngine.service(ServletEngine.java:528)
> Feb 21 16:52:45 2001: at
>
com.sybase.jaguar.servlet.ServletServiceImpl.doService(ServletServiceImpl.ja
> va:52)
> Feb 21 16:52:45 2001: at
>
com.sybase.jaguar.servlet._sk_JaguarServlet_ServletService.invoke(_sk_Jaguar
> Servlet_ServletService.java:140)
> Feb 21 16:52:45 2001: SystemException: UNKNOWN
> (DCSoft_ISPPro/ServerManager/vsAddServer - @127.0.0.1)
>
> my Exception class is:
>
> public class SMException extends java.lang.Exception
> {
>
> public SMException(int a)
> {
> // TODO: implement
> detail=a;
> }
> public String toString()
> {
> // TODO: implement
> return ("SM");
> }
> public int getNumber()
> {
> // TODO: implement
> return (detail);
> }
> public String getMessage()
> {
> // TODO: implement
> return ("SM" + detail);
> }
> private int detail;
> }
>
> in the remote interface, I have this method vsAddServer:
>
> public EJBResult vsAddServer(String connString, String serverName, String
> ipAddress, String secret, String comments) throws
java.rmi.RemoteException;
>
> and the bean implementation of this method is:
>
> public EJBResult vsAddServer(String connString, String serverName, String
> ipAddress, String secret, String comments) throws
> javax.ejb.EJBException,SMException
> {
> // TODO: implement
> Connection conn = null;
> ResultSet result = null;
> Statement stmt = null;
> PreparedStatement pstmt = null;
>
> EJBResult resultCode = new EJBResult();
> String arrString[];
> arrString = new String[1];
>
> try
> {
> secret = nullTest(secret);
> comments= nullTest(comments);
>
> Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
> ....
> ....
> ....
> ....
> if (result.isBeforeFirst())
> {
> throw new SMException(2004); I'm trying to throw this
> Exception
> }
>
> if (result != null) result.close
> }catch(SMException e)
> {
> arrString[0] = new String(e.toString());
> throw new SMException(e.getNumber());
> }catch(Exception e)
> {
> throw new javax.ejb.EJBException(e.toString());
> }finally
> {
> try
> {
> if (pstmt != null) pstmt.close();
> if (stmt != null) stmt.close();
> if (result != null) result.close();
> if (conn != null) conn.close();
> }catch(Exception e)
> {
> throw new javax.ejb.EJBException(e.toString());
> }
> pstmt = null;
> stmt = null;
> result = null;
> conn = null;
> }
> arrString[0]=new String("SM10000");
> resultCode.setArrString(arrString);
> return(resultCode);
> }
>
> I want to know how I can throw my own custom Exception from EJB method
> Many Thanks if somebody can help me
>
> Hrair Karaboyadjian
> Software Engineer
>
> DC Soft S.A.L.
> Tel: +961-1-385425
> Fax: +961-1-385428
> P.O.Box 11-337
> Beirut - Lebanon
> email: mailto:[EMAIL PROTECTED]
> http://www.dcsoftintl.com
>
> Hrair Karaboyadjian
> Software Engineer
>
> DC Soft S.A.L.
> Tel: +961-1-385425
> Fax: +961-1-385428
> P.O.Box 11-337
> Beirut - Lebanon
> email: mailto:[EMAIL PROTECTED]
> http://www.dcsoftintl.com
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".