How to catch SqlIntegrityConstraint violation exception - oracle

I have a scenario where user submits an order for a fund and a security. And if he submits the another order with same fund and security DB throws back SqlIntegrityVoilationException with error code ora-00001.
But my question here is this exception is not getting caught under java.sql.sqlintegrityconstraintviolationexception. I am able to catch this under org.springframework.dao.DataIntegrityViolationException, but I am not able to retrieve the error code (to check for ora-00001).
Anybody has any ideas how to catch that exception and retrieve the error code to check so that I can put back a custom error message like "you cannot submit a dup order for same fund and security combination".
EDIT
catch (SQLException e) {
ex = e; inOrder.setActionMessage(ex.getMessage());
}
catch (DataIntegrityViolationException e) {
ex = e; inOrder.setActionMessage(ex.getMessage());
}

Related

How to throw exception with MessageBox in Xamarin

I'm make an app which get data from API, but sometimes error will occur.
I have throw exception in my code when StatusCode is not Ok. But i have to handle it.
So, my question is how to get the exception on another thread and throw it with message box in xamarin.
ProductsNew = await Task.Run(() =>
{
ProductViewData productNewViewData = new ProductViewData();
return productNewViewData.GetProductNew("5");
});
Thanks for any help.
Put your code in try and catch block and show the error on message box.
try
{
//code
}
catch(Exception ex)
{
DisplayAlert("Error",ex.Message,"Ok");
}

Unable to catch adLDAP Exception on Laravel 5.1?

When I get an exception while running the below code, it does not return the exception message but loads Laravel’s error handling page. I’m trying to return the exception error message.
try {
$adldap = new adLDAP(Config::get('app.ldap'));
}
catch (adLDAPException $e) {
return $e;
}
I just encountered this issue and discovered that AdLDAP 5.0.0 onwards requires you to use 'adLDAP\Exceptions\adLDAPException'.
Rob Ganly

Spring WS client handling HTML instead of SOAP Fault

I have a SOAP client that is calling many different web services. In some cases some send back HTML error pages with HTTP error status codes instead of SOAP faults. I know that they should be sending SOAP faults, but I want to be able to handle this scenario. I'd like to be able to get access to the HTML error page. Right now when I get back an HTML error page with a 200 status code, a SoapMessageCreationException is thrown, which I catch. HTML error pages with HTTP error status codes throw WebServiceTransportException. How can I access the HTML data in the response at that point? I am using org.springframework.ws.transport.http.CommonsHttpMessageSender (Jakarta Commons HttpClient) as the message sender, with Spring 2.0.
I would like the code to be able to work with the default message sender if possible, otherwise, I would just check whether the instance of the message sender is CommonsHttpMessageSender or not. I prefer not to have to upgrade to Spring-WS 3/Apache HttpComponents right now, but am open to it if necessary. If I call this.webserviceTemplate.getMessageSenders(), is it ok to always take the first one ([0])?
try {
this.webserviceTemplate.sendSourceAndReceiveToResult(source,
new WebServiceMessageCallback() {
#Override
public void doWithMessage(WebServiceMessage message)
throws IOException, TransformerException {
if (LOG.isDebugEnabled()) {
// log the SOAP request
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
LOG.debug("SOAP Request Payload: " + new String(out.toByteArray()));
}
if (soapActionHttpHeader != null) {
((SoapMessage)message).setSoapAction(soapActionHttpHeader);
LOG.debug("Setting SOAP Action HTTP header to: " + soapActionHttpHeader);
}
else
LOG.debug("SOAP Action HTTP not set in the configuration.");
}
}, result);
}
catch (SoapMessageCreationException e)
{//org.springframework.ws.transport.http.CommonsHttpMessageSender
String errorMsg= "Error processing SOAP message";
LOG.info(errorMsg);
LOG.debug("Stack trace: ",e);
throw new ServiceInvocationException(errorMsg);
}
catch (WebServiceTransportException e) {
String errorMsg= "Error invoking SOAP service";
LOG.info(errorMsg);
LOG.debug("Stack trace: ",e);
throw e;
}
catch (WebServiceIOException e) {
throw new ServiceInvocationException(e);
}

OAuthException not catched with C# FacebookSDK

I try to get my code working with catching certain errors. I store the token for a user after he or she grants permission to my app (this is a WP7 app). When I try to post on the wall by using the stored token it works. When I remove the permissions on facebook it throws an OAuthException. I can't catch it it seems. My app just crashes. This is the code I used:
private object PostToFacebook()
{
_fbApp = new FacebookClient(_appsettings.faceBookToken);
FacebookAsyncCallback callback = new FacebookAsyncCallback(this.postResult);
var parameters = new Dictionary<string, object>();
parameters.Add("message", "message on wall");
try
{
_fbApp.PostAsync("me/feed", parameters, callback);
}
catch (Exception ex)
{
}
return null;
}
private void postResult(FacebookAsyncResult asyncResult)
{
if (asyncResult.Error == null)
{
status = "succes";
}
else
{
status = "error" + asyncResult.Error.Message;
}
}
The try catch doesn't catch anything and the generic exception handler in my app.xaml.cs either.
Any ideas how to catch this error so I can ask the user to authenticate again?
Put your try..catch in the callback.
You can also catch exceptions globally by handling the UnhandledException event on the App object.

NotSupportedException when adding entity via odata on windows phone

I'm using the odata client generator (DataSvcUtil.exe) in a Windows Phone 7 application. Retrieving entities and collections is fine as is updating an existing entity. But when I try to add a new entity, I get a NotSupportedException. Here's my code.
private void Button_Click(object sender, RoutedEventArgs e)
{
Drinks d =new Drink();
d.BarCode = "1234567890";
d.Description = "Test Drink";
d.Quantity = -1;
context.AddToDrinks(d);
context.BeginSaveChanges(SaveChangesOptions.Batch, OnChangesSaved, context);
}
private void OnChangesSaved(IAsyncResult result)
{
Dispatcher.BeginInvoke(() =>
{
try
{
var something = result.AsyncState;
context = result.AsyncState as DrinkTrackerModelContainer;
// Complete the save changes operation and display the response.
ShowSaveResponse("Drink Logged!", context.EndSaveChanges(result));
}
catch (DataServiceRequestException ex)
{
ShowSaveResponse("Error Logging Drink", ex.Response);
}
catch (InvalidOperationException ex)
{
ShowSaveResponse(ex.Message, null);
}
}
);
}
As soon as EndSaveChanges is called, I get the
NotSupportedException.
EDIT: I used fiddler and saw that I was in fact getting a different exception from the service. That exception data was not being shown in the debugger. Once I corrected the actual exception, the insert worked fine.
I think you have first chance exceptions turned on which is causing an internal exception thrown by the client library to surface as an exception. Try turning off First Chance Exceptions in the "Exceptions" menu in VS and running the app.
As you mentioned in your edit, the NotSupportedException was a red herring. I think that when debugging a phone app you will hit the NotSupportedException even if you have cleared the setting to break on unhandled CLR exceptions.
If you continue(F5), you'll hit an actual DataServiceRequestException exception. If it doesn't have enough information to debug it, you can follow the steps in this post to get more detailed information in the exception: http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx
I ran into the same problem yesterday, and after following the steps in the blog I was able to successfully debug the problem.

Resources