An annotation to indicate that a method throws no exception in Kotlin - exception

Since Kotlin has no checked exceptions, whether a function throws an exception is unknown. When a function throws an exception, I can use the #Throws annotation to indicate what exceptions are thrown. On the other hand, what annotation can I use to indicate that in a function all exceptions are handled and no is thrown, for better readability?

Related

JsonSerializer throwing org.codehaus.jackson.map.JsonMappingException: 4000 (through reference chain: during serialization

I'm getting
java.lang.ArrayIndexOutOfBoundsException: 4000
exception during JsonSerializer with a particular Object value and rest call is resulting in
500Internal Server Error.
below is the exception returned to Dispatcher Servlet after the call is returned back to the client from Rest API call.
org.codehaus.jackson.map.JsonMappingException: 4000 (through reference
chain:
I have tried upgrading the jackson jar version also from 1.9.2 to 1.9.5 and 1.9.13, but still throwing the same exception.
I have tried making all involved POJO objects as serializable also.
If I modify anything in JSON data call is successful with Response 200.
I can't use JSON ignore property also as fields all required.
The same code works fine for other transaction.
Please share some knowledge on it.

Exception Mapper maps exception but still throws

I implemented an ExceptionMapper for ConstraintViolationException (bean validation). When I map an Exception that extends WebApplicationException everything works perfectly (the exception is not thrown anymore, just the response formatted with mapper is commited). But in the case of ConstraintViolationException, both situations occurs. Is there any way to don't throw Exception when mapping that?

Returning an error without throwing an exception with servicestack

From what I know, exception throwing can be a little heavy. I can see that ServiceStack's Error handling suggests throwing an exception, which gets beautifully serialized to the client side.
1. How can I do the same without throwing the exception? - I see I can change the return type to object and return the HttpError instead of throwing, is this the only way?
2. Will performance improve (vs throwing)?
Returning or throwing a HttpError has the same effect, e.g:
return new HttpError(HttpStatusCode.Conflict, "SomeErrorCode");

Restler framework exception handling

how can I write exception handling in my application. I am using restler framework
RestException is handled by Restler framework to send a error response to the api user. Other than that Exception handling in restler is the usual PHP way
Best way to handle exceptions is to use try catch block where you expect them
You can detect un-handled exceptions and handle them using set_exception_handler(). Ideally you can do that at the index.php (gateway)

sendRedirect() does NOT throw IllegalStateException with Servlet 3.0 under GlassFish 3.1.1

I have a servlet with an overridden doGet method in a Dynamic Web App 3.0 targeted to GlassFish 3.1.
I'm studying for OCEJWCD exam and trying to memorize which circumstances throw which exceptions.
Due to Tomcat 6.0 only supporting Servlet 2.5 API, I have to use Glassfish 3 and I'm very confused with following situation.
Numerous old sources state that:
A response is committed as soon as the servlet starts to write
anything to the output stream. If you attempt a re-direct after the
response is committed you will receive an IllegalStateException error.
However Servlet 3.0 Final specification Section 5.3 states:
If data has been written to the response buffer, but not returned to
the client (i.e. the response is not committed), the data in the
response buffer must be cleared and replaced with the data set by
these methods. If the response is committed, these methods must throw
an IllegalStateException
What I want to know is, considering the PrintWriter.print() is committing the response, why don't these lines throw IllegalStateException?
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String url = "http://someurl.com/";
PrintWriter out = response.getWriter();
out.print("This will be written into response buffer");
response.sendRedirect(url); // sendRedirect() after writing into buffer
}
I have to note that, I am able to fetch exceptions from GlassFish server log, I can clearly see that HttpServletRequest.getRequestDispatcher().forward(req,res); followed by a HttpServletResponse.sendRedirect(url); does indeed throw an IllegalStateException in GlassFish container.
The fact is that PrintWriter.print() may commit the response. This happens if the buffer is full or if there's no buffering at all. You can check its size by calling ServletResponse.getBufferSize().
ServletResponse.flushBuffer() or PrintWriter.flush() will definitely commit the response.
So if PrintWriter.print() was committing the response, then the HttpServletResponse.sendRedirect() would indeed throw an IllegalStateException.
See also Servlet Specification, section 5.1 Buffering.
And btw., there's no RequestDispatcher.dispatch(). ;)