Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C++/CLI
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 16-Oct-12 5:20am
Comments
Wes Aday at 16-Oct-12 11:22am
   
You read the exception message....
Marcus Kramer at 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 at 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 at 16-Oct-12 12:47pm
   
So what? It looks like you have no clue on how exceptions work, need to lean it.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
CPallini at 16-Oct-12 12:51pm
   
5.
Sergey Alexandrovich Kryukov at 16-Oct-12 12:56pm
   
Thank you, Carlo.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You already posted this question here[^]. Please post in one forum only.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

When you add a simple try-catch like this
 
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).
 
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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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"
  Permalink  
Comments
Joan Murt at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 240
2 OriginalGriff 225
3 Jared Sanow 145
4 Vinay Mistry 133
0 Sergey Alexandrovich Kryukov 5,955
1 OriginalGriff 4,805
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100