User Tools

Site Tools


developer:sequencer:exception_handling

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
developer:sequencer:exception_handling [2015/02/10 17:22] – external edit 127.0.0.1developer:sequencer:exception_handling [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-======Error Handler Usage====== 
-The error handler is also a sequence. But it will be used in case of an exception, so the user knows that it is a recovery pass. 
-To create a new error handler, you have to derive from the class //ErrorHandler// built in the framework.  
-  
-<code c> 
-class MyErrorHandlerA : public eeros::sequencer::ErrorHandler 
-</code> 
  
-Then you can implement the //run()// methode including all the functionality to solve the problem causing the exception or to restart the system. 
-  
-<code c> 
-void MyErrorHandlerA::run(){ 
- Reset(); 
- Referencing(); 
- RestartSequence(); 
-} 
-</code> 
- 
-This //run()// methode will be called in the base class //Sequence// of the framework if an exception was thrown. The exception is a //SequenceException// of the framework, it can be thrown at any time. 
-e.g.: 
- 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::Initialised), 
- errorHandlerA, false, true, "TestException"); 
-</code> 
- 
-The constructor has following parameters: 
- 
-<code c> 
-SequenceException(Sequence* seqCause, Sequence::method cause, Sequence::method next, 
- ErrorHandler* error, bool toBegin, bool goToNext, std::string reason); 
-</code> 
-__Parameter //seqCause// und //cause//:__ The exception occured in the method //cause// of the sequence //seqCause//. 
- 
-__Parameter //next//:__ If //toBegin// is false and //goToNext// true, then this is the next method on which the sequence continues, after error handling has finished! 
- 
-__Parameter //toBegin//:__ Is //toBegin// true and //goToNext// false, so the sequence is restarted. (please refer also to the parameter //next//).  
-Please note: //toBegin// and //goToNext// can not be true in the same exception! 
- 
-__Parameter //error//:__ //error// is the //ErrorHandler//, which defines the behaviour on an exception. 
- 
-__Parameter //goToNext//:__ Is //toBegin// false and //goToNext// true, then the sequence continues at the //next// methode after the error handling. 
- 
-__Parameter reason:__ error message 
- 
-=====Case 1===== 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase1.png?600 | //Exception Flow Case 1//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, true, false, "TestException"); 
-</code> 
- 
-=====Case 2===== 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase2.png?600 | //Exception Flow Case 2.1//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, false, false, "TestException"); 
-</code> 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase2b.png?600 | //Exception Flow Case 2.2//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::Homed), 
- errorHandlerA, false, true, "TestException"); 
-</code> 
- 
-=====Case 3===== 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase3.png?600 | //Exception Flow Case 3//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this,  
- static_cast<eeros::sequencer::Sequence::method>&MySequence::MoveException), 0, 
- errorHandlerA, true, false, "TestException"); 
-</code> 
- 
-The //ErrorHandlerA// calls the second error handler //ErrorHandlerB//. 
- 
-<code c> 
-MyErrorHandlerB* errorHandlerB =  
- dynamic_cast<MyErrorHandlerB*>(eeros::sequencer::ErrorHandler::getErrorHandler("MyErrorHandlerB")); 
-if(!errorHandlerB){ 
- errorHandlerB = new MyErrorHandlerB("MyErrorHandlerB"); 
-} 
-errorHandlerB->run(); 
-</code> 
- 
-=====Case 4===== 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase4.png?600 | //Exception Flow Case 4.1//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, false, false, "TestException"); 
- 
-</code> 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase4b.png?600 | //Exception Flow Case 4.2//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::Homed), 
- errorHandlerA, false, true, "TestException"); 
-</code> 
- 
-=====Case 5===== 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase5.png?600 | //Exception Flow Case 5//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, true, false, "TestException"); 
-</code> 
- 
-In the case, which the sequencer will be restarted on an exception, the sub-sequencer could be kept on running state or it could also be restarted. This can be choosen by the user.  
-The code below shows how you can solve it. 
- 
-<code c> 
-MySequencer* subSequencer = dynamic_cast<MySequencer*> 
- (eeros::sequencer::Sequencer::getMainSequencer()->findSequencer("SubSequencer")); 
-bool seqIsNew = false; 
-if(!subSequencer){ 
- //use pointer to leave the object in memory!! 
- //without pointer the objetct will be destroyed. 
- subSequencer = new MySequencer("SubSequencer"); 
- seqIsNew = true; 
- //callerThread for NonBlocking Sub Sequence is a new Sequencer 
- //please take attention, if this Object looses scope, so it will be deleted!! 
- //that's why you should use a pointer to allocate memory!! 
- //else the pointer in the Executor runnables list of the Sequencer will point to nowhere!! 
-} 
-NonBlockingSubSequence* subSequence = dynamic_cast<NonBlockingSubSequence*> 
- (eeros::sequencer::Sequence::getSequence("NonBlockingSubSequence")); 
-if(!subSequence){ 
- //MyNonBlockingSubSequence is a Runnable!! 
- subSequence = new NonBlockingSubSequence("NonBlockingSubSequence", *subSequencer); 
- if(seqIsNew){ 
- //now we start the Thread of the subSequencer 
- subSequencer->start(); 
- } 
-} 
-try{  
- if(!seqIsNew && restartSequencer && subSequencer &&  
- subSequencer->getStatus() != eeros::kStopped){ 
- eeros::ExecutorService::waitForSequenceEnd(subSequencer); 
- subSequencer->start(); 
- } 
- 
-}catch(char *str){ 
- 
-} 
-</code> 
- 
-If restartSequencer is true, so the sub-sequencer will be restarted  and you have to wait for the termination of the running sub-sequencer. 
- 
-If restartSequencer is false, so the sub-sequencer runs until he finished, without restarting. 
- 
-=====Case 6===== 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase6.png?600 | //Exception Flow Case 6.1//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, false, false, "TestException"); 
- 
-</code> 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase6b.png?600 | //Exception Flow Case 6.2//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::Homed), 
- errorHandlerA, false, true, "TestException"); 
-</code> 
- 
-=====Case 7===== 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase7.png?600 | //Exception Flow Case 7//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, true, false, "TestException"); 
-</code> 
- 
-=====Case 8===== 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase8.png?600 | //Exception Flow Case 8.1//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 0, 
- errorHandlerA, false, false, "TestException"); 
-</code> 
- 
-[{{ :eeros:developer_documentation:sequencer:errorhandlercase8b.png?600 | //Exception Flow Case 8.2//}}] 
- 
-exception: 
-<code c> 
-throw new eeros::sequencer::SequenceException(this, 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::MoveException), 
- static_cast<eeros::sequencer::Sequence::method>(&MySequence::Homed), 
- errorHandlerA, false, true, "TestException"); 
-</code> 
developer/sequencer/exception_handling.1423585326.txt.gz · Last modified: 2015/02/10 17:37 (external edit)