System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Cannot open log for source 'ExceptionManagerInternalException'. You may not have write access. ---> System.ComponentModel.Win32Exception: Access is denied
--- End of inner exception stack trace ---
at System.Diagnostics.EventLogInternal.OpenForWrite(String currentMachineName)
at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at CTL.COM.ExceptionManagement.DefaultPublisher.WriteToLog(String entry, EventLogEntryType type)
at CTL.COM.ExceptionManagement.DefaultPublisher.Publish(Exception exception, NameValueCollection additionalInfo, NameValueCollection configSettings)
at CTL.COM.ExceptionManagement.ExceptionManager.PublishInternalException(Exception exception, NameValueCollection additionalInfo)
at CTL.COM.ExceptionManagement.ExceptionManager.Publish(Exception exception, NameValueCollection additionalInfo)
at CTL.COM.Services.Util.Utilities.HandleExceptions(Exception ex, APIResponse xmlResponse)
at CTL.COM.Services.Util.AcquireTicketImplementation.AcquireTicket(AcquireTicketRequest xmlRequest, AcquireTicketResponse xmlResponse)
at CTL.COM.Services.Prime.Issuer.WebServices.PrimeIssuerServices.AcquireTicket(AcquireTicketRequest xmlRequest)
--- End of inner exception stack trace ---
Any ideas? Help me please?
Related
So, I have to investigate if null InputStream goes to catch block of the code
Example code snippet::
public class TestLambda implements RequestStreamHandler {
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
try {
if (inputStream != null && inputStream.available() != 0) {
System.out.println("do something...");
}
} catch (Exception exception) {
System.out.println("in catch block");
}
My question is, if I do not put an else condition to the if block above and there is null inputStream, should the control go into catch block?
No, control won't enter the exception block unless an Exception is thrown. Just having a null inputStream alone will not cause an exception to be thrown because the if condition is checking if it is null.
I have a set of futures, each of which may throw an exception that I want to log in my way and rethrow, but this doesn't compile:
CompletableFuture<Void> lordOfFutures = CompletableFuture.allOf(future1, future3, future2)
.handle((screen, throwable) -> {
if (throwable!=null) {
LOG.error(throwable, throwable);
throw throwable;
} else {
return screen;
});
Is it possible to log the first exception that occurs and rethrow it?
handle expects a BiFunction<? super T,Throwable,? extends U> whose apply method is not allowed to throw Throwable. This applies to all functions of the java.util.function package. But you don’t need to rethrow the throwable at all:
CompletableFuture<Void> lordOfFutures = CompletableFuture.allOf(future1, future3, future2)
.whenComplete((screen, throwable) -> {
if (throwable!=null) {
LOG.error(throwable, throwable);
});
The future returned by whenComplete will have the same completion state or value as the future you’re calling it on (but only after executing the specified action). So if the future returned by allOf gets completed exceptionally, the “lordOfFutures” will be too, and otherwise, it will be completed with the same value (which is always null here).
I get the run time exception;
Run-Time Check Failure #2 - Stack around the variable 'ex' was corrupted.
for the following piece of code.
DBConnPtr CDBConnector::GetConnectionInstance()
{
if (m_pConn)
return m_pConn;
if (m_loginInfo.hostName.IsEmpty() ||
m_loginInfo.portNumber == 0 ||
m_loginInfo.userName.IsEmpty())
return m_pConn;
CString hostInfo(_T(""));
hostInfo.Format("tcp://%s:%d", m_loginInfo.hostName, m_loginInfo.portNumber);
sql::SQLString host = hostInfo;
sql::SQLString user = m_loginInfo.userName;
sql::SQLString pwd = m_loginInfo.userPwd;
try
{
sql::Driver* pDriver = get_driver_instance();
m_pConn = (DBConnPtr)pDriver->connect(host, user, pwd);
}
catch (sql::SQLException ex)
{
}
//mysql_thread_end();
return m_pConn;
}
Before moving sql::SQLString pwd = m_loginInfo.userPwd; outside the try block, it used to throw
Run-Time Check Failure #2 - Stack around the variable 'pwd' was corrupted.
Any ideas why?
Im using mysql library and trying to catch SQLException that happens at the connect call.
EDIT
Output Window after typecasting every CString to LPCTSTR:
First-chance exception at 0x75B61D4D in MyApp.exe: Microsoft C++ exception: sql::SQLException at memory location 0x0493F8C0.
First-chance exception at 0x75B61D4D in MyApp.exe: Microsoft C++ exception: sql::SQLException at memory location 0x0493F8C0.
Unhandled exception at 0x005E18A5 in MyApp.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.
As MSDN points out: When you pass a character string as an optional argument, you must cast it explicitly as LPCTSTR.
Also, this article points out the consequence if you don't do so.
If the type SQLString can be cast to LPCTSTR, change this line:
hostInfo.Format("tcp://%s:%d", m_loginInfo.hostName, m_loginInfo.portNumber);
to:
hostInfo.Format(_T("tcp://%s:%d"), LPCTSTR(m_loginInfo.hostName), LPCTSTR(m_loginInfo.portNumber));
I want to write a unit test to ensure that I get a WebException with a 404 status code thrown from a particular method.
The WebException bit is easy:
[Test]
[ExpectedException(typeof(WebFaultException))]
public void CheckForWebFaultException()
{
var myClass = new MyClass();
myClass.MyMethod();
}
However this could be a 404, a 400, 401 or any other of the myriad of other http codes.
I could do a try/catch/Assert.True but this feels like a hack. Is there a way to Assert against a property of the thrown exception?
Something like
Assert.Throws(typeof(WebFaultException), myClass.MyMethod(), wfx => wfx.StatusCode == HttpStatusCode.NotFound);
I was on the right lines, Assert.Throws actually returns the exception which was thrown.
[Test]
public void CheckForWebFaultException()
{
var myClass = new MyClass();
var ex = Assert.Throws<WebFaultException>(() => myClass.MyMethod());
Assert.AreEqual(HttpStatusCode.NotFound, ex.StatusCode);
}
Note that I've taken out the [ExpectedException(typeof(WebFaultException))] as the exception is now handled and the test will fail if this is left in.
Assert.Throws ensures that the exception was thrown by myClass.MyMethod() and the second assert checks the status code.
I have to implement an async HTTP GET in C++ and we have to be able to submit the app to the Windows 8 Store.
My problem is the following:
I've found a suitable Sample code which implements an HttpRequest class http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664
This example works if the URI is correct but throws an exception if the URI points to an invalid / non existing place (like: www.google22.com). This would be fine if I could catch the exception but I cannot figure it out how or where should I catch it.
Now some code.
This is the call to the async, concurrency::task based method which throws the exception:
try {
...
Web::HttpRequest httpRequest;
httpRequest.GetAsync(uri, cancellationTokenSource.get_token())
.then( [] (concurrency::task<std::wstring> response)
{
try {
response.get();
}
catch( ... ) {
int i = 1;
}
return response;
})
...
} catch ( ... ) {
...
}
And this is the relevant segment of the GetAsync method (the end of the method):
// Return a task that completes when the HTTP operation completes.
// We pass the callback to the continuation because the lifetime of the
// callback must exceed the operation to ensure that cancellation
// works correctly.
return completionTask.then([this, stringCallback](tuple<HRESULT, wstring> resultTuple)
{
// If the GET operation failed, throw an Exception.
CheckHResult(std::get<0>(resultTuple));
statusCode = stringCallback->GetStatusCode();
reasonPhrase = stringCallback->GetReasonPhrase();
return std::get<1>(resultTuple);
});
The CheckHResult line throws the exception, it's code:
inline void CheckHResult(HRESULT hResult)
{
if (hResult == E_ABORT)
{
concurrency::cancel_current_task();
}
else if (FAILED(hResult))
{
throw Platform::Exception::CreateException(hResult);
}
}
I have a try-catch around the GetAsync call and I also have a try-catch in the .then continuation lambda.
In the relevant Microsoft documentation ( http://msdn.microsoft.com/en-us/library/windows/apps/hh780559.aspx ) it states that exceptions thrown by a task should be catchable in the next task in the chain but somehow it doesn't work in my case. Additionally not even the try-catch around the whole call catches the exception, it just slips through everything...
Anyone had this problem? I think I've tried everything stated in the official documentations but it still lets the exception go berserk and crash the app. What do I miss?
EDIT:
I've modified the code to do nothing else but exception handling and it still doesn't catch the exception thrown by the task in .GetAsync
Cleaned-up code:
try
{
Windows::Foundation::Uri^ uri;
uri = ref new Windows::Foundation::Uri( uri_string_to_fetch );
concurrency::cancellation_token_source cancellationTokenSource = concurrency::cancellation_token_source();
Web::HttpRequest httpRequest;
OutputDebugString( L"Start to fetch the uri...\n" );
httpRequest.GetAsync(uri, cancellationTokenSource.get_token())
.then([](concurrency::task<std::wstring> response)
{
try {
response.get();
}
catch( ... ) {
OutputDebugString(L"unknown Exception");
}
})
.then([](concurrency::task<void> t)
{
try {
t.get();
// .get() didn't throw, so we succeeded.
}
catch (Platform::Exception^ e) {
// handle error
OutputDebugString(L"Platform::Exception");
}
catch (...) {
OutputDebugString(L"unknown Exception");
}
});
}
catch (Platform::Exception^ ex) {
OutputDebugString(L"Platform::Exception");
errorCallback(-1);
}
catch ( ... ) {
OutputDebugString(L"unknown Exception");
errorCallback(-2);
}
This still gives me a crash with the exception message: First-chance exception at 0x75644B32 in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x077EEC28. HRESULT:0x800C0005
Additionally when I put some breakpoints in the code it shows that the exception slips through everything before the first .then would be called. I've put breakpoints in these locations (in the simplified / cleaned up code):
before the GetAsync call
into the GetAsync, to the CheckHResult(std::get<0>(resultTuple)); line which throws the exception
into every try and catch case / block
Order of execution, tested with breakpoints:
before the GetAsync call [OK]
in the GetAsync, the line which will throw the exception [OK]
now the app crashes, slips through every try-catch, continue
now the line in the first .then gets called, in it's try block
another app level exceptions not catched by any catch block
now the first .then's catch block
second .then method's try block
and nothing more, the second .then's catch doesn't even catch any exception
And the printed debug logs, in order:
- Start to fetch the uri...
- First-chance exception at 0x75644B32 in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x082FEEF0. HRESULT:0x800C0005
- First-chance exception at 0x75644B32 in App1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
- First-chance exception at 0x75644B32 in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x082FE670. HRESULT:0x800C0005
- First-chance exception at 0x75644B32 in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x082FDD88. HRESULT:0x800C0005
- unknown Exception
What is happening??
In the Concurrency Runtime any unhandled exception that occurs during the execution of a task is deferred for later observation. In this way, you could add a task based continuation at the end of the chain and handle errors there.
Something like this:
httpRequest.GetAsync(uri, cancellationTokenSource.get_token())
.then([](concurrency::task<std::wstring> response)
{
try {
response.get();
}
catch( ... ) {
int i = 1;
}
return response;
})
.then([](concurrency::task<void> t)
{
try {
t.get();
// .get() didn't throw, so we succeeded.
}
catch (Platform::Exception::CreateException^ e) {
// handle error
}
});
The call to .get triggers any exceptions that were raised in the task chain (if any).
For more details you can read Exception Handling in the Concurrency Runtime.
This related thread may have a clue:
Visual C++ Unmanaged Code: Use /EHa or /EHsc for C++ exceptions?
If you want to catch all the asynch exceptions you can try to set your Configuration Properties-> C/C++ -> Code Generation property to "Yes with SEH exceptions (/EHa)"