media player exceptions - axwindowsmediaplayer

I'm writing a windows application. I have media player in my form. When I set the URL to something like "fsgfbnhgb" (something wrong!) the player by itself shows an error. But it's not good. I have "try" and "catch" blocks and in try block there isn't any exceptions when URL is "fgdsfgasgfas"! Because the player by itself catches the exception.
How can I set error for media player by myself?
try
{
player.URL = "fdgsdgsdg";
player.Ctlcontrols.play();
}
catch
{
snd.Play();
MessageBox.Show("An error occurred during reading the alarm music path. Check that its directory is valid.", "Alarm music error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Thank you all

You could try checking if the file exists first, inside the try{} catch{}
try{
string url = "sdahgjk";
if (!File.Exists(url))
throw new Exception("Exception Message Here");
player.Url = url;
player.Ctlcontrols.play();
}
catch
{
snd.Play();
MessageBox.Show("An error occurred during reading the alarm music path. Check that its directory is valid.", "Alarm music error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Related

TCPConnection IO Exception web application

I'm trying to read datafroma device.
The following codeworks fine on a Desktop application.
When I put it in a Web Application,it gives IO Exception.
I've turned off FireWall,
When deployed
Client inherits from TcpClientPlus
using (FaceId Client = new FaceId(textBoxDeviceIP.Text, Convert.ToInt32(textBoxDevicePort.Text)))
{
Client.SecretKey =textBoxSecretKey.Text.Trim();
string Answer;
FaceId_ErrorCode ErrorCode = Client.Execute(textBoxCommand.Text, out Answer, DeviceCodePage);
if (ErrorCode == FaceId_ErrorCode.Success)
{
textBoxAnswer.Text = Answer;
}
else
{
MessageBox.Show("Error Code: " + ErrorCode.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I've found out the reason: another connection was open at the same time.
Also, I've turned on the firewall & it worked fine.
Thanks a lot.

SSH.NET does not capture exception message

We are using Cerberus FTP server. And for the client I am using SSH.NET library to connect to server and upload a file. I was able to connect and upload files to FTP server without issue most of the time.
However when destination path does not exists on the FTP server, the SSH.NET library throws exception as expected. However Exception's Message property is empty.
var sftpClient = new SftpClient(host,username,password);
sftp.connect();
var destination = "SomeInvalidPath\myfile.txt"
using (var fs = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read))
{
try
{
sftp.UploadFile(fs, destination);
}
catch (Exception ex)
{
// ex.Message is empty ???
Logger.Current.Error(ex, "Error while FTP");
}
}
Not sure if this SSH.NET library issue or FTP server needs to propagate errors back to client?
Update 1
Stack trace
" at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags
flags, Boolean nullOnError)\r\n at
Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path,
Flags flags, SftpUploadAsyncResult asyncResult, Action1
uploadCallback)\r\n at Renci.SshNet.SftpClient.UploadFile(Stream
input, String path, Action1 uploadCallback)\r\n at XXXXXX

Gets FormatException when trying to query data to Parse.com in Unity

I'm using Parse plugin 1.5.5 for Unity 5.1.3 in order to communicate with Parse.com in Unity. I'm getting FormatException when trying to connect to Parse when there is no internet connection with following code. I was wondering if this is a bug of Parse plugin or anything I did wrong.
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Data");
query.FirstAsync().ContinueWith (task =>
{
if (task.IsCanceled)
{
Debug.Log ("parse canceled");
}
else if(task.IsFaulted)
{
Debug.Log ("parse error");
}
else
{
Debug.Log ("parse retrieved");
}
});
Error code is following.
FormatException: Input string was not in the correct format
System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono- runtime-and-classlibs/build/mcs/class/corlib/System/Int32.cs:629)
Parse.PlatformHooks+HttpRequestUnity.getStatusCode (UnityEngine.WWW www)
Parse.PlatformHooks+HttpRequestUnity+<>c__DisplayClass40+<>c__DisplayClass46.<ExecuteAsync>b__3a (UnityEngine.WWW www)
Parse.PlatformHooks+<>c__DisplayClass24.<RegisterNetworkRequest>b__23 ()
Parse.PlatformHooks+<RunDispatcher>d__2e.MoveNext ()
UnityEngine.Debug:LogException(Exception)
Parse.<RunDispatcher>d__2e:MoveNext()
Thank you,

Google.Apis.Email_Migration_v2

I am attempting to retrieve the HttpStatusCode from every UploadAsync method call. I need the status code as to properly perform an exponential back-off algorithm to retry a failed upload, display an error message to the user when not retrying the upload and to report success of the upload. I do not care how it is received, so long as it is clean and not being parsed from the Exception.Message (string) property like Tor Jonsson suggested in the link provided below.
To force the "Bad Request Error [400]" I simply provided an invalid userkey (email) in the constructor for MailResource.InsertMediaUpload.
e.g. MailResource.InsertMediaUpload(mailItem, "invalidEmail#domain.com", stream, "message/rfc822")
Problem
1) GoogleApiException.HttpStatusCode is always 0 (unavailable). Even when Exception.Message appears to contain a status code in brackets. e.g. [400]
2) Cannot find GoogleApiRequestException.
Questions
1) What is the best way to perform the exponential back-off algorithm???
2) Is this the expected behaviour for this property in this case?
3) Does GoogleApiRequestException still exist, if so where?
Side Note:
I also noticed that the GoogleApiRequestException class is no longer in the same file as GoogleApiException class. Has it been moved to another namespace or deleted? Because I would like to attempt to catch a GoogleApiRequestException object and grab its RequestError object.
I added links to the two diffs for what I mean:
Before: http://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/GoogleApiException.cs?r=a8e27790f8769c1d6aaae030bb46c79daa7cdbad
After: http://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/GoogleApiException.cs?r=d6f06e92d90b635c179013e2c287b42b82909c09
Sources
I'm using the latest binaries from NuGet (1.6.0.8-beta)
The only question I found related to my problem: (Can only post two links... heres the raw)
stackoverflow.com/questions/18985306/httpstatuscode-not-set-in-exceptions-when-using-google-net-apis
Code: (Using a custom logger to write to debugview)
public int Index; // Used to Id the process
private void TryUpload(MailResource.InsertMediaUpload upload, out IUploadProgress uploadProgress, out bool retryUpload)
{
uploadProgress = null;
retryUpload = false;
CancellationToken token;
try
{
uploadProgress = upload.UploadAsync(token).Result;
if (uploadProgress.Exception != null)
{
_logger.WriteTrace("EXCEPTION!!! Type: {0}", uploadProgress.Exception.GetType().ToString()); // Remove:
// *) Handle all of the various exceptions
if (uploadProgress.Exception is JsonReaderException)
{
JsonReaderException jreEx = uploadProgress.Exception as JsonReaderException;
_logger.WriteTrace("JsonReaderException-> Message: {0}", jreEx.Message);
}
if (uploadProgress.Exception is TokenResponseException)
{
TokenErrorResponse trEx = uploadProgress as TokenErrorResponse;
_logger.WriteTrace("TokenErrorResponse-> Message: {0}", trEx.Error);
}
if (uploadProgress.Exception is HttpRequestValidationException)
{
HttpRequestValidationException hrvEx = uploadProgress.Exception as HttpRequestValidationException;
_logger.WriteTrace("HttpRequestValidationException-> Message: {0}", hrvEx.Message);
_logger.WriteTrace("HttpRequestValidationException-> Status Code: {0}", hrvEx.GetHttpCode());
}
if (uploadProgress.Exception is GoogleApiException)
{
GoogleApiException gApiEx = uploadProgress.Exception as GoogleApiException;
_logger.WriteTrace("GoogleApiException-> Message: {0}", gApiEx.Message);
_logger.WriteTrace("GoogleApiException-> Status Code: {0}", gApiEx.HttpStatusCode);
}
}
}
catch (Exception ex)
{
_logger.WriteTrace(ex, "An exception occured while uploading...");
}
finally
{
if (uploadProgress != null)
_logger.WriteTrace("Upload Completed... Status: {0} Exception?: {1}",
uploadProgress.Status,
(uploadProgress.Exception == null) ? "None" : uploadProgress.Exception.ToString());
else
_logger.WriteTrace("Upload Aborted... Exited without returning a status!");
}
}
Output Snippet
[5224] (T101) VSLLC: EXCEPTION!!! Type: Google.GoogleApiException
[5224] (T101) VSLLC: GoogleApiException-> Message: Google.Apis.Requests.RequestError
[5224] Bad Request [400]
[5224] Errors [
[5224] Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
[5224] ]
[5224] (T101) VSLLC: GoogleApiException-> Status Code: 0
[5224] (T101) VSLLC: Upload Completed... Status: Failed Exception?: The service admin has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
[5224] Bad Request [400]
[5224] Errors [
[5224] Message[Bad Request] Location[ - ] Reason[badRequest] Domain[global]
[5224] ]
[5224]
[5224] at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[5224] at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
[5224] at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
[5224] at Google.Apis.Upload.ResumableUpload`1.d__0.MoveNext() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:line 373
Sorry for the extensive post! Thanks for your time!
The library already supports exponential back-off for 503 responses. In case of 400 (bad request) you should not retry, because you will get the same response over and over again.
Take a look in the service initializer parameter DefaultExponentialBackOffPolicy
You can also take a look in our ExponentialBackOff implementation. BackOffHandler wraps the logic and implements unsuccessful response handler and exception handler.
GoogleApiRequest doesn't exists anymore.
It looks like we are not setting the status code properly, as you can find here. I open a new issue in our issue tracker, available here - https://code.google.com/p/google-api-dotnet-client/issues/detail?id=425. Feel free to add more content to it.

Error processing GroovyPageView: getOutputStream() has already been called for this response

I have an action that writes directly to the output stream. Sometimes I get the following to errors:
Error processing GroovyPageView: getOutputStream() has already been called for this response
Caused by getOutputStream() has already been called for this response
and this one:
Executing action [getImage] of controller [buddyis.ItemController] caused exception: Runtime error executing action
Caused by Broken pipe
How can I solve these problems? The action I use is listed below.
NOTE: I use Tomcat 7.0.42, if this is important!
def getImage() {
byte [] imageByteArray = // some image bytes
response.setHeader 'Content-disposition', "attachment; filename=\"${imageName}${imageExtension}\""
response.setContentType("image/pjpeg; charset=UTF-8")
response.contentLength = imageByteArray.size()
response.outputStream.write(imageByteArray)
response.outputStream.flush()
response.outputStream.close()
return
}
I don't know why you are getting that error, however here is what I do that works everytime.
I don't call .flush() or .close()
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "filename=\"${name}\"")
response.setContentLength(imageByteArray.size())
response.outputStream << imageByteArray
Using the above it was working fine, until I found out a user can cancel a download, which caused an exception. This is the full code I use instead of response.outputStream << imageByteArray:
def outputStream = null
try {
outputStream = response.outputStream
outputStream << imageByteArray
} catch (IOException e){
log.debug('Canceled download?', e)
} finally {
if (outputStream != null){
try {
outputStream.close()
} catch (IOException e) {
log.debug('Exception on close', e)
}
}
}
I had this issue whilst running grails 2.5 on tomcat:7.0.55.3 and with the java-melody grails plugin installed. After uninstalling java-melody it worked just fine

Resources