feat: cleanup exceptions a bit

This commit is contained in:
izzy 2026-03-07 15:00:07 -05:00
parent 7c2869c5b9
commit be6af511bd
3 changed files with 34 additions and 25 deletions

View file

@ -35,6 +35,9 @@
#include "..\Minecraft.World\net.minecraft.world.item.crafting.h"
#include "Options.h"
// MinecraftConsoles Added
#include "..\Minecraft.World\Exceptions.h"
Random PlayerConnection::random;
PlayerConnection::PlayerConnection(MinecraftServer *server, Connection *connection, shared_ptr<ServerPlayer> player)
@ -88,6 +91,18 @@ void PlayerConnection::tick()
didTick = false;
tickCount++;
try
{
connection->tick();
}
catch (const IOException& e)
{
app.DebugPrintF("IOException -- %ls\n", e.information);
disconnect(DisconnectPacket::eDisconnect_None);
return;
}
connection->tick();
if(done) return;

View file

@ -1,29 +1,30 @@
#pragma once
using namespace std;
class EOFException : public std::exception
// izzint - TODO: these other exceptions should really be implemented
class EOFException : public std::runtime_error
{
};
class IllegalArgumentException : public std::exception
class IllegalArgumentException : public std::runtime_error
{
public:
wstring information;
std::wstring information;
IllegalArgumentException(const wstring& information);
IllegalArgumentException(const std::wstring& information);
};
class IOException : public std::exception
class IOException : public std::runtime_error
{
public:
wstring information;
std::wstring information;
IOException(const wstring& information);
IOException(const std::wstring& information);
};
class RuntimeException : public std::exception
class RuntimeException : public std::runtime_error
{
public:
RuntimeException(const wstring& information);
RuntimeException(const std::wstring& information);
};

View file

@ -157,9 +157,9 @@ IllegalArgumentException::IllegalArgumentException(const wstring& information)
this->information = information;
}
IOException::IOException(const wstring& information)
IOException::IOException(const wstring &info) : std::runtime_error("IOException")
{
this->information = information;
this->information = info;
}
Packet::Packet() : createTime( System::currentTimeMillis() )
@ -379,12 +379,10 @@ void Packet::writePacket(shared_ptr<Packet> packet, DataOutputStream *dos) // th
void Packet::writeUtf(const wstring& value, DataOutputStream *dos) // throws IOException TODO 4J JEV, should this declare a throws?
{
#if 0
if (value.length() > Short::MAX_VALUE)
{
throw new IOException(L"String too big");
throw IOException(L"Packet::writeUtf - String too big");
}
#endif
dos->writeShort((short)value.length());
dos->writeChars(value);
@ -394,20 +392,15 @@ wstring Packet::readUtf(DataInputStream *dis, int maxLength) // throws IOExcepti
{
short stringLength = dis->readShort();
if (stringLength > maxLength)
if (stringLength > maxLength || stringLength < 0)
{
wstringstream stream;
stream << L"Received string length longer than maximum allowed (" << stringLength << " > " << maxLength << ")";
assert(false);
// throw new IOException( stream.str() );
}
if (stringLength < 0)
{
assert(false);
// throw new IOException(L"Received string length is less than zero! Weird string!");
throw IOException(L"Packet::readUtf - Invalid string passed");
}
wstring builder = L"";
builder.reserve(stringLength);
for (int i = 0; i < stringLength; i++)
{
wchar_t rc = dis->readChar();