Project

General

Profile

Statistics
| Branch: | Revision:

root / src / nedxml / nedexception.cc @ 79bb12dc

History | View | Annotate | Download (1.39 KB)

1
//==========================================================================
2
// nedexception.cc -
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8

    
9
/*--------------------------------------------------------------*
10
  Copyright (C) 2002-2008 Andras Varga
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#include <stdio.h>
18
#include <stdarg.h>
19
#include <stdlib.h>
20
#include "commonutil.h"
21
#include "nedexception.h"
22
#include "nedelement.h"
23

    
24
NAMESPACE_BEGIN
25

    
26

    
27
#define BUFLEN 1024
28

    
29
NEDException::NEDException(const char *messagefmt...) : std::runtime_error("")
30
{
31
    char message[BUFLEN];
32
    VSNPRINTF(message, BUFLEN, messagefmt);
33
    errormsg = message;
34
}
35

    
36
NEDException::NEDException(NEDElement *context, const char *messagefmt...) : std::runtime_error("")
37
{
38
    char message[BUFLEN];
39
    VSNPRINTF(message, BUFLEN, messagefmt);
40

    
41
    const char *loc = context ? context->getSourceLocation() : NULL;
42
    if (loc)
43
        errormsg = std::string(message) + ", at " + std::string(loc);
44
    else if (context)
45
        errormsg = std::string(context->getTagName()) + ": " + message;
46
    else
47
        errormsg = message;
48
}
49

    
50
NAMESPACE_END
51