-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErr.cpp
84 lines (67 loc) · 1.61 KB
/
Err.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// err.cpp
// browser-cc
//
// Created by Nissassin Seventeen on 10/2/15.
// Copyright (c) 2015 Nissassin Seventeen. All rights reserved.
//
#include <cstdarg>
#include <string>
#include "Err.hpp"
bool Err::isSuccess() const {
return this->errType == Success;
}
const char *Err::what() const throw () {
return this->description.c_str();
}
Err::Err(ErrType errType, ...) :
runtime_error("Browser error"), errType(errType) {
va_list args;
va_start(args, errType);
switch (errType) {
case Success:
this->description = "Success";
break;
case NoLinkProvided:
this->description = "No link provided";
break;
case UnsupportedSchema:
this->description =
"Unsupported schema (currently only support http and https)";
break;
case NoHostnameProvided:
this->description = "Please provide hostname";
break;
case CannotCreateSock:
this->description = "System error. Cannot create sock";
break;
case CannotConnect:
this->description = "Cannot connect";
break;
case CannotSend:
this->description = "Cannot send request";
break;
case CannotReceive:
this->description = "Cannot receive response";
break;
case CannotResolveHostname:
this->description = "Cannot resolve hostname";
break;
case NoConnection:
this->description = "There is no connection";
break;
case DontSendButReceive:
this->description =
"Receive response without sending any request (what a weird error lol)";
break;
case DECODING:
this->description = "invalid encoding (cannot decode)";
break;
default:
this->description = "Unknown error";
break;
}
va_end(args);
}
Err::~Err() throw () {
}