• Register
1 vote
182 views

Problem :

I am very new to Python programming. My below code gives me errors :

with open(json_file) as jfile:
    try:
        json_config = json.load(jfile)
    except ValueError as e:
        raise Exception('Invalid json: {}'.format(e))

Please find below errors caused by above code.

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 103 column 9 (char 1093)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
<....>
raise Exception('Invalid json: {}'.format(e))
Exception: Invalid json: Expecting ',' delimiter: line 103 column 9 (char 1093)
Can some expert tell me how can I quickly fix above errors?
8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

I think now you are having very strange issue which is related to raising a ValueError exception inside the another caught exception. If you are looking for the quick fix for your error then you need to change below line of code
raise Exception('Invalid json: {}'.format(e))
To the below correct one.
raise Exception('Invalid json: {}'.format(e)) from None

It will make your end code as below:

with open(json_file) as jfile:
    try:
        json_config = json.load(jfile)
    except ValueError as e:
        raise Exception('Invalid json: {}'.format(e)) from None

After making above changes in your code you must get a desired result of catching the exception. Hope the solution helped you in quick fix.

8 4
5,680 points

Related questions

0 votes
1 answer 22 views
0 votes
1 answer 4 views
4 views
Problem: an exception has been thrown during the rendering of a template
asked Feb 21 charles mathews 3.9k points
0 votes
1 answer 9 views
9 views
Problem: Error occurred during initialization of VM Too small initial heap. this is strange because dtnode_heapsize is 8G DataNode maximum Java I just got this error message trying to change it to 1gig. Error occurred during initialization of VM. Too small initial heap for new size specified. I'm running 64bit
asked Feb 23 Ali 5.9k points
0 votes
1 answer 34 views
34 views
Problem: I was trying to make a Minecraft server and got the following error on startup: Error occured during initialization of VM Could not reserve enough space for object heap Error: Could not create the Java Virtual Machine Error: A fatal exception has occurred. Program will ... installed java, making sure it was 64 bit, as my computer is. Still, I get this error. Does anyone know a solution?
asked Feb 19 Ali 5.9k points
0 votes
1 answer 30 views
30 views
Does anyone know a solution?
asked Jan 4 TeamScript 13.5k points
0 votes
1 answer 17 views
17 views
Any suggestions on how to fix this?
asked Dec 30, 2020 TeamScript 13.5k points
0 votes
1 answer 37 views
37 views
I can't figure out why it's not working for me.
asked Dec 27, 2020 TeamScript 13.5k points
0 votes
1 answer 33 views
33 views
I was working on that but I got into some problems.
asked Dec 3, 2020 TeamScript 13.5k points
0 votes
1 answer 149 views
149 views
Problem : I am having a box with 8gb of ram, so I don't think the total memory is the issue. This application is running properly on boxes with 6gb or less ram. What I am trying to do is to reserve 3GB of space using -Xmx3G command under "VM ... : Error occurred during initialization of VM; Could not reserve enough space for object heap using -Xmx3G Why am I getting such error any clue?
asked Nov 26, 2019 alecxe 7.5k points