1
Hello
I am as following code:
<c:set var="exception" value="${requestScope['java.sql.SQLException']}"/>
<p class="alert alert-danger"><b>Ops!</b> Erro: <br><br>
<!-- Stack trace -->
<jsp:scriptlet>
// exception.printStackTrace();
exception.printStackTrace(new java.io.PrintWriter(out));
</jsp:scriptlet>
</p>
It’s just that mistakes come a lot:
java.sql.SQLException: ORA-20999: Aluno já cadastrado anteriormente
ORA-06512: em "DBAADV.TRG_CURSO_INSCRICAO", line 8
ORA-04088: erro durante a execução do gatilho 'DBAADV.TRG_CURSO_INSCRICAO'
ORA-06512: em "DBAADV.PROC_INSCRICAO", line 13
ORA-06512: em line 1 at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) at
oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059) at
oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522) at
oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257) at
oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587) at
I’d just like to pick up the specific error:
ORA-20999: Aluno já cadastrado anteriormente
or
Aluno já cadastrado anteriormente
My Try/catch
try {
...
} catch (SQLException ex) {
throw new ServletException(ex);
}
With getMessage() and getLocalizedMessage() nothing appeared and with getSQLState() did
cannot find symbol
– adventistaam
Nothing showed up on the console, but that doesn’t mean the messages are empty. You still need to write these variables in your default output (terminal), which you did before through the
new java.io.PrintWriter(out)
. There are several ways to send this message pro terminal. One of them is to use js throughconsole.log("")
, that will display in the terminal everything that is passed as parameter.– fwerther
I tried so:
exception.getMessage();
– adventistaam
The printStackTrace problem is that it will display the entire stack of errors, which includes more information than you want to see. The methods
getMessage()
do not redirect the output by default, IE, you will still need to send this information to the default output of your server, and there are a few different ways to do this. This may appear on the client (browser) console viaconsole.log()
; or on the server using <% out.println(Exception.getMessage()) %>. Another better solution would be to control what is displayed on the console in its server access method.– fwerther
the control would be more manual?
– adventistaam
and if you wanted to take only the first message?
– adventistaam
This error page will not always be the same message. it comes automatically, but I would like it to show in a friendly way
– adventistaam
Ah, just now I understand what you want to do! You want to display the exception message on your JSP page! Well, in that case I think the best practice would be for you to create your own exceptions and have them extend Servletexception. Then you could make a robust exception control and fire/treat them correctly.
throw new ServletException(ex);
forthrow new ServletException(ex.getMessage());
, I believe that the constructor you are using is swallowing the exception message and so will empty.– fwerther