Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I am a newbie trying to add code to a c++/CLI code.

The problem is there is a thread and it runs fine at a certain condition it calls a routine then the routine calls another routine.
After it goes back to the thread an exception happens.

I have a try{} catch{}

How can I fix it?
How to know which exception is happening?

Thanks
Eman
Posted
Comments
[no name] 16-Oct-12 11:22am    
You read the exception message....
fjdiewornncalwe 16-Oct-12 11:58am    
1) What is the exception.
2) Can you provide a small code snippet to show us where the issue happens.
From what you have provided, all we can say is what Wes already did, "Read the Exception" and deal with it.
Sergey Alexandrovich Kryukov 16-Oct-12 12:50pm    
Marcus,

You see, it looks like in this particular case this is irrelevant. I think the problem is that OP has not clue how the mechanism works, so I provided some rough answer which should be most adequate at this level. I hope so -- please see my answer.
--SA
Sergey Alexandrovich Kryukov 16-Oct-12 12:47pm    
So what? It looks like you have no clue on how exceptions work, need to lean it.
--SA

It looks like you have no clue on how exceptions work. Just learn about it — it's not trivial. A hint: exception is something which works on a whole stacks (of each tread separately, of cause) and jumps over the stack to the trial point ignoring the history of calls and returns. This is a time machine of stack.

http://en.wikipedia.org/wiki/Structured_exception_handling[^].

—SA
 
Share this answer
 
Comments
CPallini 16-Oct-12 12:51pm    
5.
Sergey Alexandrovich Kryukov 16-Oct-12 12:56pm    
Thank you, Carlo.
--SA
You already posted this question here[^]. Please post in one forum only.
 
Share this answer
 
When you add a simple try-catch like this

C++
try {
}
catch(...) {
}


you ignore the exception, you just want to catch whatever it is and do something. But if you care about the exception, then you have to explicitly name the type of the exception you want to handle. It can be by value, by reference, by pointer (which is actually by value) or, in C++/CLI by handle (hat).

C++
try {
}
catch(MyException& e1) {
}
catch(std::exception& e2) {
}
catch(ManagedException^ e3) {
}
catch(...) // if none of the above
{
}

Here are some links for you:
Exceptions in C++/CLI[^]
The try, catch, and throw Statements[^]
 
Share this answer
 
Hi Guys

Thank you all for your reply

I found out the Exception that is happenning
"Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on"

I have a label that I update from a routine that is called by the thread.

does this mean I need to update the label from inside the thread?

why is this exception happening?

Please excuse my questions I am just trying to understand.

Thanks
Eman
 
Share this answer
 
Even when I moved the Label to the thread I get the error.

"Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on"
 
Share this answer
 
Comments
Joan M 17-Oct-12 1:34am    
Emmos2011, when you want to add a comment, do it using the proper methodology:

If you plan to answer to some post, you can use the reply button on the right side of that same post.

If you want to add more information to your question, then use the "Improve question" green link that appears under the same question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900