1 /*
2  *  exceptions.h
3  *
4  *  This file is part of NEST.
5  *
6  *  Copyright (C) 2004 The NEST Initiative
7  *
8  *  NEST is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  NEST is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef EXCEPTIONS_H
24 #define EXCEPTIONS_H
25 
26 // Includes from nestkernel:
27 #include "nest_time.h"
28 
29 // Includes from sli:
30 #include "name.h"
31 #include "sliexceptions.h"
32 
33 class SLIInterpreter;
34 
35 namespace nest
36 {
37 
38 class Event;
39 
40 /**
41  * @addtogroup Exceptions Exception classes
42  * Exception classes that are thrown to indicate
43  * an error.
44  */
45 
46 /**
47  * @defgroup KernelExceptions NEST kernel exception classes
48  * Exception classes that are thrown by the NEST kernel to indicate
49  * an error.
50  * @ingroup Exceptions
51  */
52 
53 /**
54  * Base class for all Kernel exceptions.
55  * @ingroup Exceptions
56  * @ingroup KernelExceptions
57  */
58 class KernelException : public SLIException
59 {
60 public:
KernelException()61   KernelException()
62     : SLIException( "KernelException" )
63   {
64   }
65 
KernelException(char const * const what)66   KernelException( char const* const what )
67     : SLIException( what )
68   {
69   }
70 
KernelException(const std::string & what)71   KernelException( const std::string& what )
72     : SLIException( what )
73   {
74   }
75 
~KernelException()76   virtual ~KernelException() throw()
77   {
78   }
79 
80   virtual std::string
message()81   message() const
82   {
83     return std::string();
84   }
85 };
86 
87 /**
88  * Exception to be thrown if a model with the the specified name
89  * does not exist.
90  * @see UnknownModelID
91  * @ingroup KernelExceptions
92  */
93 class UnknownModelName : public KernelException
94 {
95   const Name n_;
96 
97 public:
UnknownModelName(const Name & n)98   UnknownModelName( const Name& n )
99     : KernelException( "UnknownModelName" )
100     , n_( n )
101   {
102   }
103 
throw()104   ~UnknownModelName() throw()
105   {
106   }
107   std::string message() const;
108 };
109 
110 /**
111  * Exception to be thrown if a name requested for a user-defined
112  * model exist already.
113  * @ingroup KernelExceptions
114  */
115 class NewModelNameExists : public KernelException
116 {
117   const Name n_;
118 
119 public:
NewModelNameExists(const Name & n)120   NewModelNameExists( const Name& n )
121     : KernelException( "NewModelNameExists" )
122     , n_( n )
123   {
124   }
throw()125   ~NewModelNameExists() throw()
126   {
127   }
128   std::string message() const;
129 };
130 
131 /**
132  * Exception to be thrown if a model with the the specified ID
133  * does not exist.
134  * This exception can occur if modeldict has corrupt entries.
135  * @see UnknownModelID
136  * @ingroup KernelExceptions
137  */
138 class UnknownModelID : public KernelException
139 {
140   const long id_;
141 
142 public:
UnknownModelID(long id)143   UnknownModelID( long id )
144     : KernelException( "UnknownModelID" )
145     , id_( id )
146   {
147   }
throw()148   ~UnknownModelID() throw()
149   {
150   }
151   std::string message() const;
152 };
153 
154 /**
155  * Exception to be thrown if a (neuron/synapse) model with the the specified ID
156  * is used within the network and the providing module hence cannot be
157  * uninstalled. This exception can occur if the user tries to uninstall a
158  * module.
159  * @see UnknownModelID
160  * @ingroup KernelExceptions
161  */
162 class ModelInUse : public KernelException
163 {
164   const std::string modelname_;
165 
166 public:
ModelInUse(const std::string & modelname)167   ModelInUse( const std::string& modelname )
168     : KernelException( "ModelInUse" )
169     , modelname_( modelname )
170   {
171   }
172 
throw()173   ~ModelInUse() throw()
174   {
175   }
176   std::string message() const;
177 };
178 
179 /**
180  * Exception to be thrown if the specified
181  * Synapse type does not exist.
182  * @ingroup KernelExceptions
183  */
184 class UnknownSynapseType : public KernelException
185 {
186   int synapseid_;
187   std::string synapsename_;
188 
189 public:
UnknownSynapseType(int id)190   UnknownSynapseType( int id )
191     : KernelException( "UnknownSynapseType" )
192     , synapseid_( id )
193     , synapsename_()
194   {
195   }
196 
UnknownSynapseType(std::string name)197   UnknownSynapseType( std::string name )
198     : KernelException( "UnknownSynapseType" )
199     , synapseid_()
200     , synapsename_( name )
201   {
202   }
203 
throw()204   ~UnknownSynapseType() throw()
205   {
206   }
207 
208   std::string message() const;
209 };
210 
211 /**
212  * Exception to be thrown if the specified
213  * Node does not exist.
214  * This exception is thrown, if
215  * -# an address did not point to an existing node.
216  * -# a node id did not point to an existing node.
217  * @ingroup KernelExceptions
218  */
219 
220 class UnknownNode : public KernelException
221 {
222   int id_;
223 
224 public:
UnknownNode()225   UnknownNode()
226     : KernelException( "UnknownNode" )
227     , id_( -1 )
228   {
229   }
UnknownNode(int id)230   UnknownNode( int id )
231     : KernelException( "UnknownNode" )
232     , id_( id )
233   {
234   }
235 
throw()236   ~UnknownNode() throw()
237   {
238   }
239 
240   std::string message() const;
241 };
242 
243 /**
244  * Exception to be thrown if the specified
245  * Node does not exist.
246  * This exception is thrown, if
247  * -# an address did not point to an existing node.
248  * -# a node id did not point to an existing node.
249  * @ingroup KernelExceptions
250  */
251 
252 class NoThreadSiblingsAvailable : public KernelException
253 {
254   int id_;
255 
256 public:
NoThreadSiblingsAvailable()257   NoThreadSiblingsAvailable()
258     : KernelException( "UnknownNode" )
259     , id_( -1 )
260   {
261   }
NoThreadSiblingsAvailable(int id)262   NoThreadSiblingsAvailable( int id )
263     : KernelException( "UnknownNode" )
264     , id_( id )
265   {
266   }
267 
throw()268   ~NoThreadSiblingsAvailable() throw()
269   {
270   }
271 
272   std::string message() const;
273 };
274 
275 
276 class LocalNodeExpected : public KernelException
277 {
278   int id_;
279 
280 public:
LocalNodeExpected(int id)281   LocalNodeExpected( int id )
282     : KernelException( "LocalNodeExpected" )
283     , id_( id )
284   {
285   }
286 
throw()287   ~LocalNodeExpected() throw()
288   {
289   }
290 
291   std::string message() const;
292 };
293 
294 class NodeWithProxiesExpected : public KernelException
295 {
296   int id_;
297 
298 public:
NodeWithProxiesExpected(int id)299   NodeWithProxiesExpected( int id )
300     : KernelException( "NodeWithProxiesExpected" )
301     , id_( id )
302   {
303   }
304 
throw()305   ~NodeWithProxiesExpected() throw()
306   {
307   }
308 
309   std::string message() const;
310 };
311 
312 /**
313  * Exception to be thrown if the specified
314  * receptor type does not exist in the node.
315  */
316 
317 class UnknownReceptorType : public KernelException
318 {
319   long receptor_type_;
320   std::string name_;
321 
322 public:
UnknownReceptorType(long receptor_type,std::string name)323   UnknownReceptorType( long receptor_type, std::string name )
324     : KernelException( "UnknownReceptorType" )
325     , receptor_type_( receptor_type )
326     , name_( name )
327   {
328   }
329 
throw()330   ~UnknownReceptorType() throw()
331   {
332   }
333   std::string message() const;
334 };
335 
336 /**
337  * Exception to be thrown if the specified
338  * receptor type does not accept the event type.
339  */
340 
341 class IncompatibleReceptorType : public KernelException
342 {
343   long receptor_type_;
344   std::string name_;
345   std::string event_type_;
346 
347 public:
IncompatibleReceptorType(long receptor_type,std::string name,std::string event)348   IncompatibleReceptorType( long receptor_type, std::string name, std::string event )
349     : KernelException( "IncompatibleReceptorType" )
350     , receptor_type_( receptor_type )
351     , name_( name )
352     , event_type_( event )
353   {
354   }
355 
throw()356   ~IncompatibleReceptorType() throw()
357   {
358   }
359   std::string message() const;
360 };
361 
362 /**
363  * To be thrown if a port does not exists.
364  * This exception is thrown if a specified port (or r-port) number
365  * was unknown at the specified node.
366  * @ingroup KernelExceptions
367  */
368 class UnknownPort : public KernelException
369 {
370   int id_;
371 
372 public:
UnknownPort(int id)373   UnknownPort( int id )
374     : KernelException( "UnknownPort" )
375     , id_( id )
376   {
377   }
378 
throw()379   ~UnknownPort() throw()
380   {
381   }
382 
383   std::string message() const;
384 };
385 
386 /**
387  * To be thrown if a connection is not possible.
388  * This exception is e.g. thrown if a connection was attempted with
389  * an unsupported Event type.
390  * @ingroup KernelExceptions
391  */
392 class IllegalConnection : public KernelException
393 {
394 public:
IllegalConnection()395   IllegalConnection()
396     : KernelException( "IllegalConnection" )
397     , msg_()
398   {
399   }
400 
IllegalConnection(std::string msg)401   IllegalConnection( std::string msg )
402     : KernelException( "IllegalConnection" )
403     , msg_( msg )
404   {
405   }
406 
throw()407   ~IllegalConnection() throw()
408   {
409   }
410 
411   std::string message() const;
412 
413 private:
414   std::string msg_;
415 };
416 
417 /**
418  * To be thrown if a connection does not exists but something is to be done with
419  * it.
420  * This exception is e.g. thrown if a deletion was attempted with
421  * an inexistent connection.
422  * @ingroup KernelExceptions
423  */
424 class InexistentConnection : public KernelException
425 {
426 public:
InexistentConnection()427   InexistentConnection()
428     : KernelException( "The connection does not exist" )
429     , msg_()
430   {
431   }
432 
InexistentConnection(std::string msg)433   InexistentConnection( std::string msg )
434     : KernelException( "The connection does not exist" )
435     , msg_( msg )
436   {
437   }
438 
throw()439   ~InexistentConnection() throw()
440   {
441   }
442 
443   std::string message() const;
444 
445 private:
446   std::string msg_;
447 };
448 
449 /**
450  * Exception to be thrown if a thread id outside the range encountered.
451  * @ingroup KernelExceptions
452  */
453 class UnknownThread : public KernelException
454 {
455   int id_;
456 
457 public:
UnknownThread(int id)458   UnknownThread( int id )
459     : KernelException( "UnknownThread" )
460     , id_( id )
461   {
462   }
463 
throw()464   ~UnknownThread() throw()
465   {
466   }
467 
468   std::string message() const;
469 };
470 
471 /**
472  * Exception to be thrown if an invalid delay is used in a
473  * connection.
474  * @ingroup KernelExceptions
475  */
476 class BadDelay : public KernelException
477 {
478   double delay_;
479   std::string message_;
480 
481 public:
BadDelay(double delay,std::string message)482   BadDelay( double delay, std::string message )
483     : KernelException( "BadDelay" )
484     , delay_( delay )
485     , message_( message )
486   {
487   }
488 
throw()489   ~BadDelay() throw()
490   {
491   }
492 
493   std::string message() const;
494 };
495 
496 /**
497  * Exception to be thrown by the event handler
498  * of a node if it receives an event it cannot handle.
499  * This case should be prevented by connect_sender().
500  * @ingroup KernelExceptions
501  */
502 class UnexpectedEvent : public KernelException
503 {
504 public:
UnexpectedEvent()505   UnexpectedEvent()
506     : KernelException( "UnexpectedEvent" )
507   {
508   }
509 
UnexpectedEvent(std::string msg)510   UnexpectedEvent( std::string msg )
511     : KernelException( "UnexpectedEvent" )
512     , msg_( msg )
513   {
514   }
515 
throw()516   ~UnexpectedEvent() throw()
517   {
518   }
519 
520   std::string message() const;
521 
522 private:
523   std::string msg_;
524 };
525 
526 
527 /**
528  * Exception to be thrown by a Connection object if
529  * a connection with an unsupported event type is
530  * attempted
531  * @ingroup KernelExceptions
532  */
533 class UnsupportedEvent : public KernelException
534 {
535 public:
UnsupportedEvent()536   UnsupportedEvent()
537     : KernelException( "UnsupportedEvent" )
538   {
539   }
540 
throw()541   ~UnsupportedEvent() throw()
542   {
543   }
544   std::string message() const;
545 };
546 
547 /**
548  * Exception to be thrown if a status parameter
549  * is incomplete or inconsistent.
550  * Thrown by Node::set_/get_property methods.
551  * @ingroup KernelExceptions
552  */
553 class BadProperty : public KernelException
554 {
555   std::string msg_;
556 
557 public:
558   //! @param detailed error message
BadProperty()559   BadProperty()
560     : KernelException( "BadProperty" )
561     , msg_()
562   {
563   }
BadProperty(std::string msg)564   BadProperty( std::string msg )
565     : KernelException( "BadProperty" )
566     , msg_( msg )
567   {
568   }
569 
throw()570   ~BadProperty() throw()
571   {
572   }
573 
574   std::string message() const;
575 };
576 
577 /**
578  * Exception to be thrown if a parameter
579  * cannot be set.
580  * Thrown by Node::set_/get_property methods.
581  * @ingroup KernelExceptions
582  */
583 class BadParameter : public KernelException
584 {
585   std::string msg_;
586 
587 public:
588   //! @param detailed error message
BadParameter()589   BadParameter()
590     : KernelException( "BadParameter" )
591     , msg_()
592   {
593   }
BadParameter(std::string msg)594   BadParameter( std::string msg )
595     : KernelException( "BadParameter" )
596     , msg_( msg )
597   {
598   }
599 
throw()600   ~BadParameter() throw()
601   {
602   }
603 
604   std::string message() const;
605 };
606 
607 /**
608  * Exception to be thrown if the dimensions
609  * of two or more objects do not agree.
610  * Thrown by Node::set_/get_property methods.
611  * @ingroup KernelExceptions
612  */
613 class DimensionMismatch : public KernelException
614 {
615   int expected_;
616   int provided_;
617   std::string msg_;
618 
619 public:
DimensionMismatch()620   DimensionMismatch()
621     : KernelException( "DimensionMismatch" )
622     , expected_( -1 )
623     , provided_( -1 )
624     , msg_( "" )
625   {
626   }
627 
DimensionMismatch(int expected,int provided)628   DimensionMismatch( int expected, int provided )
629     : KernelException( "DimensionMismatch" )
630     , expected_( expected )
631     , provided_( provided )
632     , msg_( "" )
633   {
634   }
635 
DimensionMismatch(const std::string & msg)636   DimensionMismatch( const std::string& msg )
637     : KernelException( "DimensionMismatch" )
638     , expected_( -1 )
639     , provided_( -1 )
640     , msg_( msg )
641   {
642   }
643 
644 
throw()645   ~DimensionMismatch() throw()
646   {
647   }
648 
649   std::string message() const;
650 };
651 
652 /**
653  * Exception to be thrown if a problem with the
654  * distribution of elements is encountered
655  * @ingroup KernelExceptions
656  */
657 class DistributionError : public KernelException
658 {
659 public:
DistributionError()660   DistributionError()
661     : KernelException( "DistributionError" )
662   {
663   }
throw()664   ~DistributionError() throw()
665   {
666   }
667 
668   std::string message() const;
669 };
670 
671 /**
672  * Exception to be thrown on prototype construction if Time objects
673  * incompatible. This exception is to be thrown by the default constructor of
674  * nodes which require that Time objects have properties wrt resolution.
675  * @ingroup KernelExceptions
676  * @see InvalidTimeInModel
677  */
678 class InvalidDefaultResolution : public KernelException
679 {
680 public:
681   /**
682    * @note model should be passed from get_name() to ensure that
683    *             names of copied models are reported correctly.
684    * @param model     name of model causing problem
685    * @param property  name of property conflicting
686    * @param value     value of property conflicting
687    */
InvalidDefaultResolution(const std::string & model,const Name & property,const Time & value)688   InvalidDefaultResolution( const std::string& model, const Name& property, const Time& value )
689     : KernelException( "InvalidDefaultResolution" )
690     , model_( model )
691     , prop_( property )
692     , val_( value )
693   {
694   }
throw()695   ~InvalidDefaultResolution() throw()
696   {
697   }
698 
699   std::string message() const;
700 
701 private:
702   const std::string model_;
703   const Name prop_;
704   const Time val_;
705 };
706 
707 /**
708  * Exception to be thrown on instance construction if Time objects incompatible.
709  * This exception is to be thrown by the copy constructor of nodes which
710  * require that Time objects have properties wrt resolution.
711  * @ingroup KernelExceptions
712  * @see InvalidDefaultResolution
713  */
714 class InvalidTimeInModel : public KernelException
715 {
716 public:
717   /**
718   * @note model should be passed from get_name() to ensure that
719   *             names of copied models are reported correctly.
720    * @param model     name of model causing problem
721    * @param property  name of property conflicting
722    * @param value     value of property conflicting
723    */
InvalidTimeInModel(const std::string & model,const Name & property,const Time & value)724   InvalidTimeInModel( const std::string& model, const Name& property, const Time& value )
725     : KernelException( "InvalidTimeInModel" )
726     , model_( model )
727     , prop_( property )
728     , val_( value )
729   {
730   }
throw()731   ~InvalidTimeInModel() throw()
732   {
733   }
734 
735   std::string message() const;
736 
737 private:
738   const std::string model_;
739   const Name prop_;
740   const Time val_;
741 };
742 
743 /**
744  * Exception to be thrown if a Time object should be multiple of the resolution.
745  * @see TimeMultipleRequired
746  * @ingroup KernelExceptions
747  */
748 class StepMultipleRequired : public KernelException
749 {
750 public:
751   /**
752   * @note model should be passed from get_name() to ensure that
753   *             names of copied models are reported correctly.
754    * @param model     name of model causing problem
755    * @param property  name of property conflicting
756    * @param value     value of property conflicting
757    */
StepMultipleRequired(const std::string & model,const Name & property,const Time & value)758   StepMultipleRequired( const std::string& model, const Name& property, const Time& value )
759     : KernelException( "StepMultipleRequired" )
760     , model_( model )
761     , prop_( property )
762     , val_( value )
763   {
764   }
throw()765   ~StepMultipleRequired() throw()
766   {
767   }
768 
769   std::string message() const;
770 
771 private:
772   const std::string model_;
773   const Name prop_;
774   const Time val_;
775 };
776 
777 /**
778  * Exception to be thrown if a Time object should be a multiple of another.
779  * @see StepMultipleRequired
780  * @ingroup KernelExceptions
781  */
782 class TimeMultipleRequired : public KernelException
783 {
784 public:
785   /**
786   * @note model should be passed from get_name() to ensure that
787   *             names of copied models are reported correctly.
788    * @param model    name of model causing problem
789    * @param name_a   name of dividend
790    * @param value_a  value of dividend
791    * @param name_b   name of divisor
792    * @param value_b  value of divisor
793    */
TimeMultipleRequired(const std::string & model,const Name & name_a,const Time & value_a,const Name & name_b,const Time & value_b)794   TimeMultipleRequired( const std::string& model,
795     const Name& name_a,
796     const Time& value_a,
797     const Name& name_b,
798     const Time& value_b )
799     : KernelException( "StepMultipleRequired" )
800     , model_( model )
801     , prop_a_( name_a )
802     , val_a_( value_a )
803     , prop_b_( name_b )
804     , val_b_( value_b )
805   {
806   }
throw()807   ~TimeMultipleRequired() throw()
808   {
809   }
810 
811   std::string message() const;
812 
813 private:
814   const std::string model_;
815   const Name prop_a_;
816   const Time val_a_;
817   const Name prop_b_;
818   const Time val_b_;
819 };
820 
821 /**
822  * Exception to be thrown if a GSL solver does not return GSL_SUCCESS
823  * @ingroup KernelExceptions
824  */
825 class GSLSolverFailure : public KernelException
826 {
827 public:
828   /**
829   * @note model should be passed from get_name() to ensure that
830   *             names of copied models are reported correctly.
831   * @param model name of model causing problem
832   * @param status exit status of the GSL solver
833   */
GSLSolverFailure(const std::string & model,const int status)834   GSLSolverFailure( const std::string& model, const int status )
835     : KernelException( "GSLSolverFailure" )
836     , model_( model )
837     , status_( status )
838   {
839   }
throw()840   ~GSLSolverFailure() throw()
841   {
842   }
843 
844   std::string message() const;
845 
846 private:
847   const std::string model_;
848   const int status_;
849 };
850 
851 /**
852  * Exception to be thrown if numerical instabilities are detected.
853  * @ingroup KernelExceptions
854  */
855 class NumericalInstability : public KernelException
856 {
857 public:
858   /**
859    * @note model should be passed from get_name() to ensure that
860    *             names of copied models are reported correctly.
861    * @param model name of model causing problem
862    */
NumericalInstability(const std::string & model)863   NumericalInstability( const std::string& model )
864     : KernelException( "NumericalInstability" )
865     , model_( model )
866   {
867   }
throw()868   ~NumericalInstability() throw()
869   {
870   }
871 
872   std::string message() const;
873 
874 private:
875   const std::string model_;
876 };
877 
878 /**
879  * Exception to be thrown if when trying to delete an entry from
880  * DynamicRecordablesMap that does not exist.
881  * @ingroup KernelExceptions
882  */
883 class KeyError : public KernelException
884 {
885   const Name key_;
886   const std::string map_type_;
887   const std::string map_op_;
888 
889 public:
KeyError(const Name & key,const std::string & map_type,const std::string & map_op)890   KeyError( const Name& key, const std::string& map_type, const std::string& map_op )
891     : KernelException( "KeyError" )
892     , key_( key )
893     , map_type_( map_type )
894     , map_op_( map_op )
895   {
896   }
897 
throw()898   ~KeyError() throw()
899   {
900   }
901   std::string message() const;
902 };
903 
904 /**
905  * Exception to be thrown if an internal error occures.
906  * @ingroup KernelExceptions
907 */
908 class InternalError : public KernelException
909 {
910   std::string msg_;
911 
912 public:
913   //! @param detailed error message
InternalError()914   InternalError()
915     : KernelException( "InternalError" )
916     , msg_()
917   {
918   }
InternalError(std::string msg)919   InternalError( std::string msg )
920     : KernelException( "InternalError" )
921     , msg_( msg )
922   {
923   }
924 
throw()925   ~InternalError() throw()
926   {
927   }
928 
929   std::string message() const;
930 };
931 
932 
933 #ifdef HAVE_MUSIC
934 /**
935  * Exception to be thrown if a music_event_out_proxy is generated, but the music
936  * port is unmapped.
937  * @ingroup KernelExceptions
938  */
939 class MUSICPortUnconnected : public KernelException
940 {
941 public:
942   /**
943   * @note model should be passed from get_name() to ensure that
944   *             names of copied models are reported correctly.
945    * @param model     name of model causing problem
946    * @param portname  name of MUSIC port
947    */
MUSICPortUnconnected(const std::string & model,const std::string & portname)948   MUSICPortUnconnected( const std::string& model, const std::string& portname )
949     : KernelException( "MUSICPortUnconnected" )
950     , model_( model )
951     , portname_( portname )
952   {
953   }
throw()954   ~MUSICPortUnconnected() throw()
955   {
956   }
957 
958   std::string message() const;
959 
960 private:
961   const std::string model_;
962   const std::string portname_;
963 };
964 
965 /**
966  * Exception to be thrown if a music_event_out_proxy is generated, but the
967  * music port has no width.
968  * @ingroup KernelExceptions
969  */
970 class MUSICPortHasNoWidth : public KernelException
971 {
972 public:
973   /**
974   * @note model should be passed from get_name() to ensure that
975   *             names of copied models are reported correctly.
976    * @param model     name of model causing problem
977    * @param portname  name of music port
978    */
MUSICPortHasNoWidth(const std::string & model,const std::string & portname)979   MUSICPortHasNoWidth( const std::string& model, const std::string& portname )
980     : KernelException( "MUSICPortHasNoWidth" )
981     , model_( model )
982     , portname_( portname )
983   {
984   }
throw()985   ~MUSICPortHasNoWidth() throw()
986   {
987   }
988 
989   std::string message() const;
990 
991 private:
992   const std::string model_;
993   const std::string portname_;
994 };
995 
996 
997 /**
998  * Exception to be thrown if the user tries to change the name of an already
999  * published port.
1000  * @ingroup KernelExceptions
1001  */
1002 class MUSICPortAlreadyPublished : public KernelException
1003 {
1004 public:
1005   /**
1006    * @note model should be passed from get_name() to ensure that
1007    *             names of copied models are reported correctly.
1008    * @param model     name of model causing problem
1009    */
MUSICPortAlreadyPublished(const std::string & model,const std::string & portname)1010   MUSICPortAlreadyPublished( const std::string& model, const std::string& portname )
1011     : KernelException( "MUSICPortAlreadyPublished" )
1012     , model_( model )
1013     , portname_( portname )
1014   {
1015   }
throw()1016   ~MUSICPortAlreadyPublished() throw()
1017   {
1018   }
1019 
1020   std::string message() const;
1021 
1022 private:
1023   const std::string model_;
1024   const std::string portname_;
1025 };
1026 
1027 /**
1028 * Exception to be thrown if the user tries to change the name of an already
1029 * published port.
1030 * @ingroup KernelExceptions
1031 */
1032 class MUSICSimulationHasRun : public KernelException
1033 {
1034 public:
1035   /**
1036   * @note model should be passed from get_name() to ensure that
1037   *             names of copied models are reported correctly.
1038    * @param model     name of model causing problem
1039    */
MUSICSimulationHasRun(const std::string & model)1040   MUSICSimulationHasRun( const std::string& model )
1041     : KernelException( "MUSICSimulationHasRun" )
1042     , model_( model )
1043   {
1044   }
throw()1045   ~MUSICSimulationHasRun() throw()
1046   {
1047   }
1048 
1049   std::string message() const;
1050 
1051 private:
1052   const std::string model_;
1053 };
1054 
1055 
1056 /**
1057  * Exception to be thrown if the user tries to map a channel that exceeds the
1058  * width of the MUSIC port.
1059  * @ingroup KernelExceptions
1060  */
1061 class MUSICChannelUnknown : public KernelException
1062 {
1063 public:
1064   /**
1065   * @note model should be passed from get_name() to ensure that
1066   *             names of copied models are reported correctly.
1067    * @param model     name of model causing problem
1068    */
MUSICChannelUnknown(const std::string & model,const std::string & portname,int channel)1069   MUSICChannelUnknown( const std::string& model, const std::string& portname, int channel )
1070     : KernelException( "MUSICChannelUnknown" )
1071     , portname_( portname )
1072     , channel_( channel )
1073     , model_( model )
1074   {
1075   }
throw()1076   ~MUSICChannelUnknown() throw()
1077   {
1078   }
1079 
1080   std::string message() const;
1081 
1082 private:
1083   const std::string portname_;
1084   const int channel_;
1085   const std::string model_;
1086 };
1087 
1088 /**
1089  * Exception to be thrown if the user tries to use a port that is not known to
1090  * NEST.
1091  * @ingroup KernelExceptions
1092  */
1093 class MUSICPortUnknown : public KernelException
1094 {
1095 public:
MUSICPortUnknown(const std::string & portname)1096   MUSICPortUnknown( const std::string& portname )
1097     : KernelException( "MUSICPortUnknown" )
1098     , portname_( portname )
1099   {
1100   }
throw()1101   ~MUSICPortUnknown() throw()
1102   {
1103   }
1104 
1105   std::string message() const;
1106 
1107 private:
1108   const std::string portname_;
1109 };
1110 
1111 /**
1112  * Exception to be thrown if the user tries to map a channel that exceeds the
1113  * width of the MUSIC port.
1114  * @ingroup KernelExceptions
1115  */
1116 class MUSICChannelAlreadyMapped : public KernelException
1117 {
1118 public:
1119   /**
1120   * @note model should be passed from get_name() to ensure that
1121   *             names of copied models are reported correctly.
1122    * @param model     name of model causing problem
1123    */
MUSICChannelAlreadyMapped(const std::string & model,const std::string & portname,int channel)1124   MUSICChannelAlreadyMapped( const std::string& model, const std::string& portname, int channel )
1125     : KernelException( "MUSICChannelAlreadyMapped" )
1126     , portname_( portname )
1127     , channel_( channel )
1128     , model_( model )
1129   {
1130   }
throw()1131   ~MUSICChannelAlreadyMapped() throw()
1132   {
1133   }
1134 
1135   std::string message() const;
1136 
1137 private:
1138   const std::string portname_;
1139   const int channel_;
1140   const std::string model_;
1141 };
1142 
1143 #endif
1144 
1145 #ifdef HAVE_MPI
1146 class MPIPortsFileUnknown : public KernelException
1147 {
1148 public:
MPIPortsFileUnknown(const index node_id)1149   explicit MPIPortsFileUnknown( const index node_id )
1150     : node_id_( node_id )
1151   {
1152   }
1153 
1154   std::string message() const;
1155 
1156 private:
1157   const index node_id_;
1158 };
1159 #endif
1160 
1161 class UnmatchedSteps : public KernelException
1162 {
1163 public:
UnmatchedSteps(int steps_left,int total_steps)1164   UnmatchedSteps( int steps_left, int total_steps )
1165     : current_step_( total_steps - steps_left )
1166     , total_steps_( total_steps )
1167   {
1168   }
1169 
1170   std::string message() const;
1171 
1172 private:
1173   const int current_step_;
1174   const int total_steps_;
1175 };
1176 
1177 class BackendPrepared : public KernelException
1178 {
1179 public:
BackendPrepared(const std::string & backend)1180   BackendPrepared( const std::string& backend )
1181     : backend_( backend )
1182   {
1183   }
1184 
BackendPrepared(std::string && backend)1185   BackendPrepared( std::string&& backend )
1186     : backend_( std::move( backend ) )
1187   {
1188   }
1189 
1190 
1191   std::string message() const;
1192 
1193 private:
1194   const std::string backend_;
1195 };
1196 
1197 class BackendNotPrepared : public KernelException
1198 {
1199 public:
BackendNotPrepared(const std::string & backend)1200   BackendNotPrepared( const std::string& backend )
1201     : backend_( backend )
1202   {
1203   }
1204 
BackendNotPrepared(std::string && backend)1205   BackendNotPrepared( std::string&& backend )
1206     : backend_( std::move( backend ) )
1207   {
1208   }
1209 
1210   std::string message() const;
1211 
1212 private:
1213   const std::string backend_;
1214 };
1215 
1216 class LayerExpected : public KernelException
1217 {
1218 public:
LayerExpected()1219   LayerExpected()
1220     : KernelException( "LayerExpected" )
1221   {
1222   }
throw()1223   ~LayerExpected() throw()
1224   {
1225   }
1226 
1227   std::string message() const;
1228 };
1229 
1230 class LayerNodeExpected : public KernelException
1231 {
1232 public:
LayerNodeExpected()1233   LayerNodeExpected()
1234     : KernelException( "LayerNodeExpected" )
1235   {
1236   }
throw()1237   ~LayerNodeExpected() throw()
1238   {
1239   }
1240 
1241   std::string message() const;
1242 };
1243 
1244 } // namespace nest
1245 
1246 #endif
1247