The generated Java exception classes are handled in the same way as any other Java exception classes. The server-side implementation throws the exceptions, and the clients must catch them. For example, a client to the sample interface above would have to make a call like this:
// ...
String prediction = null;
try{
prediction = wService.getForecast("New York");
}
catch(NoReportForCity nor){
try
{
prediction = wService.getForecast
(nor.closestKnownCity);
}
catch(NoReportForCity nor2) {
System.out.println("No reports available for NY or
closest known city.");
}
}
You have now learned how IDL exceptions are mapped to Java to generate corresponding Java code and how such generated code is used in your own code. In the next lesson, you will learn about the IDL-to-Java mapping for IDL unions and how to use the resulting Java.