Catch MFC exception - visual-c++

Trying to catch MFC exception with macros:
TRY
{
// Do something to throw an exception.
}
CATCH(CException, e)
{
}
END_CATCH
How to get this error description message ?

Use CException::GetErrorMessage. You get the text with this call.

Related

groovy spock prints stacktrace though exception is catched

I have a spock test, which calls some service:
when:
def x = service.call()
then:
!x
Inside service I have:
def call() {
try {
doCall() // method, which throws an exception
} catch (e) {
false
}
}
So I expect method to return false and test to pass. However, test invocation from IDE prints stacktrace of the exception, though it is catched.
Purpose of the test is not to know whether exception was thrown, but just assert returned result is false, so I don't want to use Specification.thrown
First of all - check what specific exception gets thrown and gets outside the try-catch block. You have to be aware that following code in Groovy:
try {
// do something
} catch (e) {
// do something with exception
}
is an equivalent of:
try {
// do something
} catch (Exception e) {
// do something with exception
}
It means that java.lang.Throwable and all its children classes (except java.lang.Exception) are not caught inside your try catch. For instance:
def call() {
try {
throw new Error('Something wrong happened')
} catch (e) {
false
}
}
This exception won't get caught by try-catch and you will see something like this in the console log:
java.lang.Error: Something wrong happened
at com.github.wololock.micronaut.TestSpec$Service.call(TestSpec.groovy:22)
at com.github.wololock.micronaut.TestSpec.test(TestSpec.groovy:13)
It happens, because java.lang.Error extends java.lang.Throwable and it is not a child class of java.lang.Exception.
If you want to catch all possible exceptions that may happened to your code you would have to use Throwable inside the catch block, something like this:
def call() {
try {
throw new Error('Something wrong happened')
} catch (Throwable e) {
false
}
}

Will Quartz.net job will run on the next iteration even if there is any exception

Probably a stupid question... but here goes anyway...
I would like to know if the quartz.net job will be active to run on the next iteration though there is an exception( which is handled) in the current iteration. Can anyone please explain me if my understanding is correct?
public void Execute(IJobExecutionContext context)
{
_logProvider.Info("Started..");
try
{
_service.Calculate();
}
catch (Exception ex)
{
_logProvider.Error("Error " + ex);
}
}
Thanks
The simple answer is: yes, it will execute on next iteration.
Actually this is related to general .NET exception handling, rather then quartz.net behaviour:
if you have function that catches any exceptions - exceptions will not be visible outside of that function. In other words, code like
public void SomeMethod()
{
try
{
//some logic that can generate exception
}
catch (Exception ex)
{
}
}
is the same as
public void SomeMethod()
{
//some logic that NEVER generates the exception
}
In scope of quartz.net:
The only type of exception that you are allowed to throw from the execute method is JobExecutionException.
otherwise you will have unhandled exception in AppDomain. You can find more in Quartz.net Job unhandled exception behaviour SO question

Axis fault : faultString: java.io.IOException for suitetalk

I am trying to use NetSuite's suiteTalk java api for writing an interface between our lotus notes system and NetSuite.
The first error thrown by the code was a class def not found error.
for :
sun/security.provider/sun.class
sun/security.provider/sun$1.class
sun/security.provider/NativePRNG.class
I figured out that rt.jar in lotus notes was actually missing this files. So I added these class files from the jdk1.6 i had downloaded separately. Once I fixed that I started getting axis.Faults error.
Here is the simple login code that I am trying to execute from lotus note agent:
public void loginTest(){
NetSuitePortType _port=null;
// In order to use SSL forwarding for SOAP message. Refer to FAQ for details
System.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory");
// Locate the NetSuite web service
NetSuiteServiceLocator serviceLocator= new NetSuiteServiceLocator();
//Get the service port
try {
_port=serviceLocator.getNetSuitePort();
} catch (ServiceException e) {
System.out.println("Error in intializing GlobalSuiteTalkSetup");
e.printStackTrace();
}
// Setting client timeout to 2 hours for long running operatotions
((NetSuiteBindingStub) _port).setTimeout(60*60*1000*2);
try {
// Populate Passport object with all login information
Passport passport = new Passport();
RecordRef role = new RecordRef();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
passport.setEmail("username");
passport.setPassword("password.");
role.setInternalId("3");
passport.setRole(role);
passport.setAccount("111111");
// Login to NetSuite
System.out.print("\nLogging into NetSuite");
System.out.print(" Username: " + passport.getEmail());
System.out.print(" Account: " + passport.getAccount());
System.out.print(" password: " + passport.getPassword());
System.out.print(" role: " + passport.getRole());
Status status;
status = (_port.login(passport)).getStatus();
// Process the response
if (status.isIsSuccess() == true)
{
System.out.print("\nThe login was successful and a new session has been created.");
} else
{
// Should never get here since any problems with the
// login should have resulted in a SOAP fault
System.out.print("Login failed");
//System.out.print(getStatusDetails(status));
}
} catch (InvalidVersionFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidCredentialsFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientPermissionFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExceededRequestLimitFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnexpectedErrorFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidAccountFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Error thrown by code:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.io.IOException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.io.IOException
at org.apache.axis.components.net.SunJSSESocketFactory.initFactory(SunJSSESocketFactory.java:88)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:79)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.netsuite.webservices.platform_2015_1.NetSuiteBindingStub.login(NetSuiteBindingStub.java:12799)
at Login.loginTest(Unknown Source)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
{http://xml.apache.org/axis/}hostname:
java.io.IOException
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.netsuite.webservices.platform_2015_1.NetSuiteBindingStub.login(NetSuiteBindingStub.java:12799)
at Login.loginTest(Unknown Source)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
Caused by: java.io.IOException
at org.apache.axis.components.net.SunJSSESocketFactory.initFactory(SunJSSESocketFactory.java:88)
at org.apache.axis.components.net.JSSESocketFactory.create(JSSESocketFactory.java:79)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
... 14 more
I found the solution for this issue. For anyone who might get similar issue can get some clue from this solution :
The issue was because of the following statement that I had put in the code.
System.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory");
This statement is necessary when using Sun' JVM but since Lotus Notes uses IBM's JVM, setting axis.socketSecureFactory to org.apache.axis.components.net.SunFakeTrustSocketFactory made the system to look for Sun classes which not absent in IBM's JVM.
No need to add the missing classes from Sun JVM to rt.jat as I had done before. Just comment that statement and use the axis path available frpm NetSuite
Don't forget to put the patch in Note's /JVM/Lib/EXT folder and restart Lotus Notes before trying to run the code..

GPars forkOffChild exception handling

I'm using GPars' fork/join. When I throw an exception after calling forkOffChild, it gets buried.
For example:
def myRecursiveClosure = { boolean top ->
try {
if (!top) {
throw new RuntimeException('child had a problem')
} else {
forkOffChild(false)
}
} catch (Exception exc) {
println 'Exception handled internally'
throw exc
}
}
try {
GParsPool.withPool {
GParsPool.runForkJoin(true, myRecursiveClosure)
}
} catch (Exception exc) {
println 'Exception handled externally'
throw exc
}
Here, I set a flag so I know the closure has been called recursively. Then, I throw an exception, which gets caught 'internally', but the re-throw is never caught 'externally'. So I am not aware that the forked child failed.
I tried the exception handler also, but it doesn't seem to get called either.
Is this expected behavior, or am I doing something wrong? Are there any strategies to help with this? I can't have the child silently fail.
Thanks!
The important piece here is that forkOffChild() doesn't wait for the child to run. It merely schedules it for execution. So you cannot expect the forkOffChild() method to propagate exceptions from the child, since they are likely to happen long after the parent has returned from the forkOffChild() method.
Typically, however, a parent is interested in the outcome of the child computations, so it at some point after forking off collects the results using the getChildrenResults() method. This gives you back a list of calculated values or re-throws potential exceptions.
This snippet shows a minimal change to get the expected behavior:
try {
if (!top) {
throw new RuntimeException('child had a problem')
} else {
forkOffChild(false)
println childrenResults
}
} catch (Exception exc) {
println 'Exception handled internally'
throw exc
}

Thread needs to be run continuously even exception occurs in it

My application uses a thread which should be running continuously. If any exception it should log that exception and should not stop. currently my code is like below. Can any one help me?
void methodname()
{
try
{
while(1)
executable statements
}
catch
{
log exception
}
}
It needs be something like this:
while(1)
{
try
{
}
catch()
{
//log the exception
}
//continue looping
}
You have to try/catch the exceptions inside the loop - right now your code exits the loop when an exception is thrown.

Resources