Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to catch exceptions from a stack object
    primarykey
    data
    text
    <p>hope you're having a good day.</p> <p>I'm working on a class to wrap the Berkley C Networking API, so far I've only gotten a TCP server/client going. </p> <p>The issue I'm having ironically is not with the networking, but with the stack and heap. Perhaps I simply don't understand it fully, but when I use something like: <code> ClientSocket *mysock = new ClientSocket(); </code> And just call functions using the -> operator, it works perfectly fine - my SocketException class gets caught no problem, if an error occurs.</p> <p>But, when I use: <code> ClientSocket mysock; </code> And any exceptions get thrown while calling a function using the . operator, it shows: <code> terminate called after throwing an instance of 'SocketException' Aborted </code> And just throws me back to a terminal prompt.</p> <p>Forgot to add, I am wrapping the calls in try/catch blocks.</p> <p>I'm aware that the first example is using the 'new' keyword to return a pointer to the new ClientSocket instance on the heap, and the second is for the stack, but I don't know the problem.</p> <p>I'm thinking that I'm missing something about pointers/references/stack/heap, but I have no idea what is happening. The code often runs just fine, but if any exceptions are thrown.... >:(</p> <p>EDIT: On the links page, Client.cxx and Server.cxx are the example files! Thanks for pointing that out, Eric. Help with this would be greatly appreciated. The sources for this project are at:<br> links to all the files: <a href="http://furryhead.co.cc/problem.html" rel="nofollow">http://furryhead.co.cc/problem.html</a> <br> (I couldn't paste more than 2 links, and I have 4 files so this will have to do until someone can merge the links into my post) Beware: Socket.cxx is rather large, as it contains ServerSocket, ClientSocket, and SocketException definitions.</p> <p>The commands to compile all the above files are:<br> g++ -c Socket.cxx -o Socket.o<br> g++ -c Server.cxx -o Server.o<br> g++ -c Client.cxx -o Client.o<br> g++ Server.o Socket.o -o server<br> g++ Client.o Socket.o -o client</p> <p>Thanks!</p> <p>Little update, as per Jon's recommendation, I looked up the docs for the socket functions and it now has better error reporting - I check the 'errno' variable and throw an exception based on that. (That, and I don't set it to nonblocking... ;) ) - Just wanted to update and say thanks! :D</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload