Skip to content

Commit f2e6355

Browse files
committed
feat: Inherit std::exception
Signed-off-by: Yash Pandey (YP) <[email protected]>
1 parent 8540825 commit f2e6355

17 files changed

+150
-188
lines changed

casbin/casbin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
#include "enforcer.h"
2121
#include "enforcer_cached.h"
2222
#include "enforcer_synced.h"
23+
#include "exception.h"

casbin/exception.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2021 The casbin Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#ifndef CASBIN_CPP_EXCEPTION
218
#define CASBIN_CPP_EXCEPTION
319

casbin/exception/casbin_adapter_exception.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

casbin/exception/casbin_adapter_exception.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
/*
2+
* Copyright 2021 The casbin Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#ifndef CASBIN_CPP_EXCEPTION_CASBIN_ADAPTER_EXCEPTION
218
#define CASBIN_CPP_EXCEPTION_CASBIN_ADAPTER_EXCEPTION
319

4-
#include <string>
5-
620
namespace casbin {
721

822
// Exception class for Casbin Adapter Exception.
9-
class CasbinAdapterException{
10-
std::string error_message;
11-
public:
12-
CasbinAdapterException(std::string error_message);
23+
class CasbinAdapterException : std::logic_error {
24+
public:
25+
using std::logic_error::logic_error;
1326
};
1427

1528
} // namespace casbin

casbin/exception/casbin_enforcer_exception.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

casbin/exception/casbin_enforcer_exception.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
/*
2+
* Copyright 2021 The casbin Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#ifndef CASBIN_CPP_EXCEPTION_CASBIN_ENFORCER_EXCEPTION
218
#define CASBIN_CPP_EXCEPTION_CASBIN_ENFORCER_EXCEPTION
319

4-
#include <string>
5-
620
namespace casbin {
721

822
// Exception class for Casbin Enforcer Exception.
9-
class CasbinEnforcerException{
10-
std::string error_message;
11-
public:
12-
CasbinEnforcerException(std::string error_message);
23+
class CasbinEnforcerException : std::runtime_error {
24+
public:
25+
using std::runtime_error::runtime_error;
1326
};
1427

1528
} // namespace casbin

casbin/exception/casbin_rbac_exception.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

casbin/exception/casbin_rbac_exception.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
/*
2+
* Copyright 2021 The casbin Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#ifndef CASBIN_CPP_EXCEPTION_CASBIN_RBAC_EXCEPTION
218
#define CASBIN_CPP_EXCEPTION_CASBIN_RBAC_EXCEPTION
319

4-
#include <string>
5-
620
namespace casbin {
721

822
// Exception class for Casbin Adapter Exception.
9-
class CasbinRBACException{
10-
std::string error_message;
11-
public:
12-
CasbinRBACException(std::string error_message);
23+
class CasbinRBACException : std::invalid_argument {
24+
public:
25+
using std::invalid_argument::invalid_argument;
1326
};
1427

1528
} // namespace casbin

casbin/exception/illegal_argument_exception.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

casbin/exception/illegal_argument_exception.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
/*
2+
* Copyright 2021 The casbin Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#ifndef CASBIN_CPP_EXCEPTION_ILLEGAL_ARGUMENT_EXCEPTION
218
#define CASBIN_CPP_EXCEPTION_ILLEGAL_ARGUMENT_EXCEPTION
319

4-
#include <string>
5-
620
namespace casbin {
721

822
// Exception class for illegal arguments.
9-
class IllegalArgumentException{
10-
std::string error_message;
11-
public:
12-
IllegalArgumentException(std::string error_message);
23+
class IllegalArgumentException : std::invalid_argument {
24+
public:
25+
using std::invalid_argument::invalid_argument;
1326
};
1427

1528
} // namespace casbin

0 commit comments

Comments
 (0)