The below code do connects to the server successfully. It is a working code.

Now for example is not the server avaliable. So I receive this error even that I have put
this in a try{}catch{}

The error is below, and I wonder how I can shut this error off so it isn´t shown in the software?
"The remote server returned an error: (500) Internal Server Error."

String^ currentLine = "";
String^ getText = "";
try
{
	Chilkat::SFtp^ sftp = gcnew Chilkat::SFtp();
	sftp->UnlockComponent("key");
	
	sftp->ConnectTimeoutMs = 5000; //  Set some timeouts, in milliseconds:
	sftp->IdleTimeoutMs = 15000;

	int port = 2222;
	String^ hostname = "folder.hosting.com";
	sftp->Connect(hostname, port);
	sftp->AuthenticatePw("username","password");
	sftp->InitializeSftp();

	String^ handle1 = "";
	try
	{
		handle1 = sftp->OpenFile("folder/File1.txt", "readOnly", "openExisting");
		if( handle1 != nullptr ) //The file DOES  exist
		{
			int numBytes = sftp->GetFileSize32(handle1, false, true);
			getText = sftp->ReadFileText(handle1,numBytes,"ansi");
			currentLine = getText;							
		}
	}
	catch(Exception^ ex){}
	sftp->CloseHandle(handle1);
}
catch(Exception^ ex)
{
}

I really wonder why the try/catch doesn´t prevent this error from showing?

Shouldn´t the catch prevent this error from occuring?

Do you know, which line of code is returning this error?

Hi

I maybe wrong! but I don't think there's any problems with the try/catch. What you are getting back from the remote server is "it's own internal server error".
You need to find out why the remote server is generating this error?, could it be invalid requests etc...

The response your getting back is really what you need to be able to create your own schema to be able to deal with server responses at your end, so you need to parse out these response codes etc & then act upon them.

Yes it seemed to be: "it's own internal server error".

However now the hosting server do work so I do not get this error anymore. I coldn´t visit the homepage from where the file was either. So the server did have a problem.

Now I dont get the error so I cant see where in the code the problem was. I beleive it could be for this line:

handle1 = sftp->OpenFile("folder/File1.txt", "readOnly", "openExisting");

However I do wonder if there is any general method to not show this error messagebox is it is occuring. ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.